Rename CustomeKeyboardListener to KeyboardEventHandler

pull/410/head
Xin Yao 4 years ago
parent a13ded263b
commit 5b230a718b
  1. 14
      lib/src/widgets/keyboard_listener.dart
  2. 4
      lib/src/widgets/raw_editor.dart

@ -9,8 +9,8 @@ typedef CursorMoveCallback = void Function(
typedef InputShortcutCallback = void Function(InputShortcut? shortcut); typedef InputShortcutCallback = void Function(InputShortcut? shortcut);
typedef OnDeleteCallback = void Function(bool forward); typedef OnDeleteCallback = void Function(bool forward);
class CustomKeyboardListener { class KeyboardEventHandler {
CustomKeyboardListener(this.onCursorMove, this.onShortcut, this.onDelete); KeyboardEventHandler(this.onCursorMove, this.onShortcut, this.onDelete);
final CursorMoveCallback onCursorMove; final CursorMoveCallback onCursorMove;
final InputShortcutCallback onShortcut; final InputShortcutCallback onShortcut;
@ -86,21 +86,23 @@ class CustomKeyboardListener {
return KeyEventResult.ignored; return KeyEventResult.ignored;
} }
final isShortcutModifierPressed =
isMacOS ? event.isMetaPressed : event.isControlPressed;
if (_moveKeys.contains(key)) { if (_moveKeys.contains(key)) {
onCursorMove( onCursorMove(
key, key,
isMacOS ? event.isAltPressed : event.isControlPressed, isMacOS ? event.isAltPressed : event.isControlPressed,
isMacOS ? event.isMetaPressed : event.isAltPressed, isMacOS ? event.isMetaPressed : event.isAltPressed,
event.isShiftPressed); event.isShiftPressed);
} else if (isMacOS } else if (isShortcutModifierPressed && _shortcutKeys.contains(key)) {
? event.isMetaPressed
: event.isControlPressed && _shortcutKeys.contains(key)) {
onShortcut(_keyToShortcut[key]); onShortcut(_keyToShortcut[key]);
} else if (key == LogicalKeyboardKey.delete) { } else if (key == LogicalKeyboardKey.delete) {
onDelete(true); onDelete(true);
} else if (key == LogicalKeyboardKey.backspace) { } else if (key == LogicalKeyboardKey.backspace) {
onDelete(false); onDelete(false);
} else {
return KeyEventResult.ignored;
} }
return KeyEventResult.ignored; return KeyEventResult.handled;
} }
} }

@ -106,7 +106,7 @@ class RawEditorState extends EditorState
final GlobalKey _editorKey = GlobalKey(); final GlobalKey _editorKey = GlobalKey();
// Keyboard // Keyboard
late CustomKeyboardListener _keyboardListener; late KeyboardEventHandler _keyboardListener;
KeyboardVisibilityController? _keyboardVisibilityController; KeyboardVisibilityController? _keyboardVisibilityController;
StreamSubscription<bool>? _keyboardVisibilitySubscription; StreamSubscription<bool>? _keyboardVisibilitySubscription;
bool _keyboardVisible = false; bool _keyboardVisible = false;
@ -340,7 +340,7 @@ class RawEditorState extends EditorState
tickerProvider: this, tickerProvider: this,
); );
_keyboardListener = CustomKeyboardListener( _keyboardListener = KeyboardEventHandler(
handleCursorMovement, handleCursorMovement,
handleShortcut, handleShortcut,
handleDelete, handleDelete,

Loading…
Cancel
Save