Skip to content

Commit

Permalink
Add web search context menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Apr 12, 2023
1 parent f28341c commit 968f703
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/src/home/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:fpdart/fpdart.dart';
import 'package:highlight/highlight.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:multi_split_view/multi_split_view.dart';
import 'package:url_launcher/url_launcher.dart';

class EditorWidget extends StatefulHookConsumerWidget {
const EditorWidget({Key? key}) : super(key: key);
Expand Down Expand Up @@ -256,6 +257,7 @@ class _CodeFieldWidgetState extends ConsumerState<_CodeFieldWidget> {

final selectedText =
value.selection.textInside(value.text);
final lang = ref.watch(editorLanguageStateProvider);

if (selectedText.isNotEmpty) {
buttonItems.addAll([
Expand Down Expand Up @@ -283,6 +285,18 @@ class _CodeFieldWidgetState extends ConsumerState<_CodeFieldWidget> {
);
},
),
if (selectedText.split(' ').length == 1)
ContextMenuButtonItem(
label: 'Web search',
onPressed: () async {
final link = Uri.https(
'google.com',
'search',
{'q': '$selectedText in $lang language'},
);
await launchUrl(link);
},
),
]);
}

Expand Down

0 comments on commit 968f703

Please sign in to comment.