Skip to content

fix(editor): implement editor shortcut action for home and end keys to fix exception about unimplemented ScrollToDocumentBoundaryIntent #1937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/src/widgets/raw_editor/raw_editor_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,29 @@ class QuillEditorInsertEmbedIntent extends Intent {

final Attribute type;
}

class NavigateToDocumentBoundaryAction
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to document this class.

extends ContextAction<ScrollToDocumentBoundaryIntent> {
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,
),
);
}
}
15 changes: 14 additions & 1 deletion lib/src/widgets/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Comment on lines +704 to +715
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember if this change was required to fix this bug though there is a possibility that this is redundant.

}, {
...?widget.configurations.customShortcuts
}),
Expand Down Expand Up @@ -1674,7 +1686,8 @@ class QuillRawEditorState extends EditorState
IndentSelectionIntent: _indentSelectionAction,
QuillEditorApplyHeaderIntent: _applyHeaderAction,
QuillEditorApplyCheckListIntent: _applyCheckListAction,
QuillEditorApplyLinkIntent: QuillEditorApplyLinkAction(this)
QuillEditorApplyLinkIntent: QuillEditorApplyLinkAction(this),
ScrollToDocumentBoundaryIntent: NavigateToDocumentBoundaryAction(this)
};

@override
Expand Down