bang and search

This commit is contained in:
Fabian Freund
2025-02-13 14:29:37 +01:00
parent fe4baa58f5
commit e09219e07c
21 changed files with 499 additions and 314 deletions
@@ -12,6 +12,7 @@ import 'package:lensai/features/geckoview/features/search/presentation/widgets/s
import 'package:lensai/features/geckoview/features/search/presentation/widgets/search_modules/history_suggestions.dart';
import 'package:lensai/features/geckoview/features/search/presentation/widgets/search_modules/search_suggestions.dart';
import 'package:lensai/features/geckoview/features/search/presentation/widgets/search_modules/tab_search.dart';
import 'package:lensai/utils/uri_parser.dart' as uri_parser;
class SearchScreen extends HookConsumerWidget {
final String? initialSearchText;
@@ -37,13 +38,11 @@ class SearchScreen extends HookConsumerWidget {
ref.listen(
selectedBangDataProvider(),
(previous, next) {
if (next.hasValue) {
if ((previous?.hasValue ?? false) && previous!.value != next.value) {
showBangIcon.value = true;
}
selectedBang.value = next.value;
if (previous != next) {
showBangIcon.value = true;
}
selectedBang.value = next;
},
);
@@ -77,18 +76,31 @@ class SearchScreen extends HookConsumerWidget {
textEditingController: searchTextController,
focusNode: searchFocusNode,
autofocus: true,
onSubmitted: (text) async {
if (Uri.tryParse(text) case final Uri url) {
await ref
.read(tabRepositoryProvider.notifier)
.addTab(url: url);
onSubmitted: (value) async {
if (value.isNotEmpty) {
var newUrl =
uri_parser.tryParseUrl(value, eagerParsing: true);
if (context.mounted) {
ref
.read(bottomSheetControllerProvider.notifier)
.dismiss();
if (newUrl == null) {
final defaultSearchBang = ref
.read(selectedBangDataProvider()) ??
await ref.read(defaultSearchBangDataProvider.future);
context.pop();
newUrl = defaultSearchBang?.getUrl(value);
}
if (newUrl != null) {
await ref
.read(tabRepositoryProvider.notifier)
.addTab(url: newUrl);
if (context.mounted) {
ref
.read(bottomSheetControllerProvider.notifier)
.dismiss();
context.pop();
}
}
}
},
@@ -12,6 +12,7 @@ import 'package:lensai/presentation/widgets/speech_to_text_button.dart';
class SearchField extends HookConsumerWidget {
final TextEditingController textEditingController;
final FocusNode? focusNode;
final Widget? label;
final bool autofocus;
final void Function(String)? onSubmitted;
final bool showSuggestions;
@@ -25,6 +26,7 @@ class SearchField extends HookConsumerWidget {
required this.onSubmitted,
required this.activeBang,
required this.showSuggestions,
this.label,
this.focusNode,
this.showBangIcon = true,
this.autofocus = false,
@@ -70,7 +72,7 @@ class SearchField extends HookConsumerWidget {
child: UrlIcon(activeBang!.getUrl(''), iconSize: 24.0),
)
: null,
label: const Text('Search'),
label: label ?? const Text('Search'),
// hintText: 'Ask anything...',
floatingLabelBehavior: FloatingLabelBehavior.always,
suffixIcon: hasText
@@ -81,8 +81,8 @@ class HistorySuggestions extends HookConsumerWidget {
subtitle: suggestion.description.mapNotNull(
(description) => Text(
description,
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
onTap: () async {
@@ -118,20 +118,30 @@ class TabSearch extends HookConsumerWidget {
),
),
),
subtitle: MarkdownBody(
data: (bodyHasMatch && !urlHasMatch)
? result.content!
: result.highlightedUrl ?? result.url.toString(),
styleSheet: MarkdownStyleSheet(
p: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
subtitle: (bodyHasMatch || urlHasMatch)
? MarkdownBody(
data: bodyHasMatch
? result.content!
: result.highlightedUrl!,
styleSheet: MarkdownStyleSheet(
p: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context)
.colorScheme
.onSurfaceVariant,
),
a: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context)
.colorScheme
.onSurfaceVariant,
decoration: TextDecoration.none,
),
),
a: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
decoration: TextDecoration.none,
),
),
),
)
: Text(
result.url.toString(),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
onTap: () async {
await ref
.read(tabRepositoryProvider.notifier)