diff --git a/apps/weblibre/lib/features/geckoview/features/search/domain/providers/engine_suggestions.dart b/apps/weblibre/lib/features/geckoview/features/search/domain/providers/engine_suggestions.dart index e8889b75..40894a0a 100644 --- a/apps/weblibre/lib/features/geckoview/features/search/domain/providers/engine_suggestions.dart +++ b/apps/weblibre/lib/features/geckoview/features/search/domain/providers/engine_suggestions.dart @@ -23,17 +23,35 @@ import 'package:riverpod/riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:rxdart/rxdart.dart'; import 'package:weblibre/features/geckoview/domain/providers.dart'; +import 'package:weblibre/features/popular_sites/domain/repositories/popular_sites.dart'; import 'package:weblibre/features/user/domain/repositories/general_settings.dart'; part 'engine_suggestions.g.dart'; @Riverpod() class EngineSuggestions extends _$EngineSuggestions { - Future getAutocompleteSuggestion(String query) { - return ref + /// Inline ghost-text completion for the omnibar. Prefers the engine's own + /// autocomplete (history/top-domains); when that yields nothing, falls back + /// to a popular-domain prefix match from the bundled Tranco-derived + /// `sites.db` so typing "git" still completes to "github.com" without any + /// local history. + Future getAutocompleteSuggestion(String query) async { + final engineResult = await ref .read(engineSuggestionsServiceProvider) .getAutocompleteSuggestion(query) .then((result) => result?.text); + + if (engineResult != null) { + return engineResult; + } + + if (!ref.mounted) return null; + + final popularSites = await ref + .read(popularSitesRepositoryProvider.notifier) + .searchByPrefix(query, limit: 1); + + return popularSites.isEmpty ? null : popularSites.first.domain; } Future addQuery(