From 5d9ad020c7082896df8fb716025b9d0f2f8a3c59 Mon Sep 17 00:00:00 2001 From: Ellet <73608287+ellet0@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:09:39 +0300 Subject: [PATCH] fix(editor): implement editor shortcut action for home and end keys to fix exception about unimplemented ScrollToDocumentBoundaryIntent (#1937) * fix(editor): implement editor shortcut action for home and end keys to fix thrown exception about unimplemented ScrollToDocumentBoundaryIntent action --- .../raw_editor/raw_editor_actions.dart | 26 +++++++++++++++++++ .../widgets/raw_editor/raw_editor_state.dart | 15 ++++++++++- 2 files changed, 40 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 63ee48d6..a343f03f 100644 --- a/lib/src/widgets/raw_editor/raw_editor_actions.dart +++ b/lib/src/widgets/raw_editor/raw_editor_actions.dart @@ -580,3 +580,29 @@ class QuillEditorInsertEmbedIntent extends Intent { final Attribute type; } + +class NavigateToDocumentBoundaryAction + extends ContextAction { + NavigateToDocumentBoundaryAction(this.state); + + final QuillRawEditorState state; + + @override + Object? invoke( + ScrollToDocumentBoundaryIntent intent, [ + BuildContext? context, + ]) { + return Actions.invoke( + context!, + UpdateSelectionIntent( + state.textEditingValue, + intent.forward + ? TextSelection.collapsed( + offset: state.controller.plainTextEditingValue.text.length, + ) + : 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..1f2b7ff4 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: NavigateToDocumentBoundaryAction(this) }; @override