From d0bcca76e93c8d3fc0f366ead594002a5881e52a Mon Sep 17 00:00:00 2001 From: Nicolas Dion-Bouchard Date: Tue, 25 Jan 2022 21:08:29 -0500 Subject: [PATCH] Fix certain keys not working on web when editor is a child of a scroll view (#304) (#618) Co-authored-by: Nicolas Dion Bouchard --- lib/src/widgets/editor.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 675e1f7a..bc7c9071 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -469,10 +469,26 @@ class QuillEditorState extends State floatingCursorDisabled: widget.floatingCursorDisabled, ); - return _selectionGestureDetectorBuilder.build( + final editor = _selectionGestureDetectorBuilder.build( behavior: HitTestBehavior.translucent, child: child, ); + + if (kIsWeb) { + // Intercept RawKeyEvent on Web to prevent it from propagating to parents + // that might interfere with the editor key behavior, such as + // SingleChildScrollView. Thanks to @wliumelb for the workaround. + // See issue https://github.com/singerdmx/flutter-quill/issues/304 + return RawKeyboardListener( + onKey: (_) {}, + focusNode: FocusNode( + onKey: (node, event) => KeyEventResult.skipRemainingHandlers, + ), + child: editor, + ); + } + + return editor; } @override