From 8fa754dafb0e9817b25ebea748dbb223195a8668 Mon Sep 17 00:00:00 2001 From: Ellet Date: Thu, 20 Jun 2024 23:50:18 +0300 Subject: [PATCH] fix(editor): implement editor shortcut action for home and end keys to fix exception about unimplemented ScrollToDocumentBoundaryIntent --- .../raw_editor/raw_editor_actions.dart | 32 +++++++++++++++++++ .../widgets/raw_editor/raw_editor_state.dart | 15 ++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/src/widgets/raw_editor/raw_editor_actions.dart b/lib/src/widgets/raw_editor/raw_editor_actions.dart index 80774d20..e57dd228 100644 --- a/lib/src/widgets/raw_editor/raw_editor_actions.dart +++ b/lib/src/widgets/raw_editor/raw_editor_actions.dart @@ -577,3 +577,35 @@ class QuillEditorInsertEmbedIntent extends Intent { final Attribute type; } + +class QuillEditorUpdateCursorLocationAction + extends ContextAction { + QuillEditorUpdateCursorLocationAction(this.state); + + final QuillRawEditorState state; + + @override + Object? invoke(ScrollToDocumentBoundaryIntent intent, + [BuildContext? context]) { + if (intent.forward) { + return Actions.invoke( + context!, + UpdateSelectionIntent( + state.textEditingValue, + TextSelection.collapsed( + offset: state.controller.plainTextEditingValue.text.length, + ), + SelectionChangedCause.keyboard, + ), + ); + } + return Actions.invoke( + context!, + UpdateSelectionIntent( + state.textEditingValue, + const TextSelection.collapsed(offset: 0), + SelectionChangedCause.keyboard, + ), + ); + } +} diff --git a/lib/src/widgets/raw_editor/raw_editor_state.dart b/lib/src/widgets/raw_editor/raw_editor_state.dart index 6f146b8f..ccea2632 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state.dart @@ -701,6 +701,18 @@ class QuillRawEditorState extends EditorState control: !isDesktopMacOS, meta: isDesktopMacOS, ): const OpenSearchIntent(), + + // Navigate to the start or end of the document + SingleActivator( + LogicalKeyboardKey.home, + control: !isDesktopMacOS, + meta: isDesktopMacOS, + ): const ScrollToDocumentBoundaryIntent(forward: false), + SingleActivator( + LogicalKeyboardKey.end, + control: !isDesktopMacOS, + meta: isDesktopMacOS, + ): const ScrollToDocumentBoundaryIntent(forward: true), }, { ...?widget.configurations.customShortcuts }), @@ -1674,7 +1686,8 @@ class QuillRawEditorState extends EditorState IndentSelectionIntent: _indentSelectionAction, QuillEditorApplyHeaderIntent: _applyHeaderAction, QuillEditorApplyCheckListIntent: _applyCheckListAction, - QuillEditorApplyLinkIntent: QuillEditorApplyLinkAction(this) + QuillEditorApplyLinkIntent: QuillEditorApplyLinkAction(this), + ScrollToDocumentBoundaryIntent: QuillEditorUpdateCursorLocationAction(this) }; @override