diff --git a/lib/src/widgets/keyboard_listener.dart b/lib/src/widgets/keyboard_listener.dart index 782321db..b1b868aa 100644 --- a/lib/src/widgets/keyboard_listener.dart +++ b/lib/src/widgets/keyboard_listener.dart @@ -9,8 +9,8 @@ typedef CursorMoveCallback = void Function( typedef InputShortcutCallback = void Function(InputShortcut? shortcut); typedef OnDeleteCallback = void Function(bool forward); -class CustomKeyboardListener { - CustomKeyboardListener(this.onCursorMove, this.onShortcut, this.onDelete); +class KeyboardEventHandler { + KeyboardEventHandler(this.onCursorMove, this.onShortcut, this.onDelete); final CursorMoveCallback onCursorMove; final InputShortcutCallback onShortcut; @@ -86,21 +86,23 @@ class CustomKeyboardListener { return KeyEventResult.ignored; } + final isShortcutModifierPressed = + isMacOS ? event.isMetaPressed : event.isControlPressed; if (_moveKeys.contains(key)) { onCursorMove( key, isMacOS ? event.isAltPressed : event.isControlPressed, isMacOS ? event.isMetaPressed : event.isAltPressed, event.isShiftPressed); - } else if (isMacOS - ? event.isMetaPressed - : event.isControlPressed && _shortcutKeys.contains(key)) { + } else if (isShortcutModifierPressed && _shortcutKeys.contains(key)) { onShortcut(_keyToShortcut[key]); } else if (key == LogicalKeyboardKey.delete) { onDelete(true); } else if (key == LogicalKeyboardKey.backspace) { onDelete(false); + } else { + return KeyEventResult.ignored; } - return KeyEventResult.ignored; + return KeyEventResult.handled; } } diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index a67f6f3a..66330d55 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -106,7 +106,7 @@ class RawEditorState extends EditorState final GlobalKey _editorKey = GlobalKey(); // Keyboard - late CustomKeyboardListener _keyboardListener; + late KeyboardEventHandler _keyboardListener; KeyboardVisibilityController? _keyboardVisibilityController; StreamSubscription? _keyboardVisibilitySubscription; bool _keyboardVisible = false; @@ -340,7 +340,7 @@ class RawEditorState extends EditorState tickerProvider: this, ); - _keyboardListener = CustomKeyboardListener( + _keyboardListener = KeyboardEventHandler( handleCursorMovement, handleShortcut, handleDelete,