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 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;
}
}

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

Loading…
Cancel
Save