Skip to content

Commit

Permalink
Swap order of shortcut map merging so that customShortcuts are added …
Browse files Browse the repository at this point in the history
…first and override existing duplicate trigger shortcuts by absorbing the input first (#2089)

Co-authored-by: ryanscott0515 <[email protected]>
  • Loading branch information
InstrinsicAutomations and ryanscott0515 authored Aug 2, 2024
1 parent 23f66b3 commit 4c04fcf
Showing 1 changed file with 186 additions and 181 deletions.
367 changes: 186 additions & 181 deletions lib/src/editor/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,187 +533,192 @@ class QuillRawEditorState extends EditorState
child: QuillStyles(
data: _styles!,
child: Shortcuts(
shortcuts: mergeMaps<ShortcutActivator, Intent>({
// shortcuts added for Desktop platforms.
const SingleActivator(
LogicalKeyboardKey.escape,
): const HideSelectionToolbarIntent(),
SingleActivator(
LogicalKeyboardKey.keyZ,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const UndoTextIntent(SelectionChangedCause.keyboard),
SingleActivator(
LogicalKeyboardKey.keyY,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const RedoTextIntent(SelectionChangedCause.keyboard),

// Selection formatting.
SingleActivator(
LogicalKeyboardKey.keyB,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.bold),
SingleActivator(
LogicalKeyboardKey.keyU,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.underline),
SingleActivator(
LogicalKeyboardKey.keyI,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.italic),
SingleActivator(
LogicalKeyboardKey.keyS,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.strikeThrough),
SingleActivator(
LogicalKeyboardKey.backquote,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.inlineCode),
SingleActivator(
LogicalKeyboardKey.tilde,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.codeBlock),
SingleActivator(
LogicalKeyboardKey.keyB,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.blockQuote),
SingleActivator(
LogicalKeyboardKey.keyK,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyLinkIntent(),

// Lists
SingleActivator(
LogicalKeyboardKey.keyL,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.ul),
SingleActivator(
LogicalKeyboardKey.keyO,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.ol),
SingleActivator(
LogicalKeyboardKey.keyC,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const QuillEditorApplyCheckListIntent(),

// Indents
SingleActivator(
LogicalKeyboardKey.keyM,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const IndentSelectionIntent(true),
SingleActivator(
LogicalKeyboardKey.keyM,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const IndentSelectionIntent(false),

// Headers
SingleActivator(
LogicalKeyboardKey.digit1,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h1),
SingleActivator(
LogicalKeyboardKey.digit2,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h2),
SingleActivator(
LogicalKeyboardKey.digit3,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h3),
SingleActivator(
LogicalKeyboardKey.digit4,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h4),
SingleActivator(
LogicalKeyboardKey.digit5,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h5),
SingleActivator(
LogicalKeyboardKey.digit6,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h6),
SingleActivator(
LogicalKeyboardKey.digit0,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.header),

SingleActivator(
LogicalKeyboardKey.keyG,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorInsertEmbedIntent(Attribute.image),

SingleActivator(
LogicalKeyboardKey.keyF,
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),

// Arrow key scrolling
SingleActivator(
LogicalKeyboardKey.arrowUp,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(direction: AxisDirection.up),
SingleActivator(
LogicalKeyboardKey.arrowDown,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(direction: AxisDirection.down),
SingleActivator(
LogicalKeyboardKey.pageUp,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(
direction: AxisDirection.up, type: ScrollIncrementType.page),
SingleActivator(
LogicalKeyboardKey.pageDown,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(
direction: AxisDirection.down, type: ScrollIncrementType.page),
}, {
...?widget.configurations.customShortcuts
}),
/// Merge with widget.configurations.customShortcuts
/// first to allow user's defined shortcuts to take
/// priority when activation triggers are the same
shortcuts: mergeMaps<ShortcutActivator, Intent>(
{...?widget.configurations.customShortcuts},
{
// shortcuts added for Desktop platforms.
const SingleActivator(
LogicalKeyboardKey.escape,
): const HideSelectionToolbarIntent(),
SingleActivator(
LogicalKeyboardKey.keyZ,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const UndoTextIntent(SelectionChangedCause.keyboard),
SingleActivator(
LogicalKeyboardKey.keyY,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const RedoTextIntent(SelectionChangedCause.keyboard),

// Selection formatting.
SingleActivator(
LogicalKeyboardKey.keyB,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.bold),
SingleActivator(
LogicalKeyboardKey.keyU,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.underline),
SingleActivator(
LogicalKeyboardKey.keyI,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.italic),
SingleActivator(
LogicalKeyboardKey.keyS,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.strikeThrough),
SingleActivator(
LogicalKeyboardKey.backquote,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.inlineCode),
SingleActivator(
LogicalKeyboardKey.tilde,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.codeBlock),
SingleActivator(
LogicalKeyboardKey.keyB,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.blockQuote),
SingleActivator(
LogicalKeyboardKey.keyK,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyLinkIntent(),

// Lists
SingleActivator(
LogicalKeyboardKey.keyL,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.ul),
SingleActivator(
LogicalKeyboardKey.keyO,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const ToggleTextStyleIntent(Attribute.ol),
SingleActivator(
LogicalKeyboardKey.keyC,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const QuillEditorApplyCheckListIntent(),

// Indents
SingleActivator(
LogicalKeyboardKey.keyM,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const IndentSelectionIntent(true),
SingleActivator(
LogicalKeyboardKey.keyM,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
shift: true,
): const IndentSelectionIntent(false),

// Headers
SingleActivator(
LogicalKeyboardKey.digit1,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h1),
SingleActivator(
LogicalKeyboardKey.digit2,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h2),
SingleActivator(
LogicalKeyboardKey.digit3,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h3),
SingleActivator(
LogicalKeyboardKey.digit4,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h4),
SingleActivator(
LogicalKeyboardKey.digit5,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h5),
SingleActivator(
LogicalKeyboardKey.digit6,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h6),
SingleActivator(
LogicalKeyboardKey.digit0,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.header),

SingleActivator(
LogicalKeyboardKey.keyG,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const QuillEditorInsertEmbedIntent(Attribute.image),

SingleActivator(
LogicalKeyboardKey.keyF,
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),

// Arrow key scrolling
SingleActivator(
LogicalKeyboardKey.arrowUp,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(direction: AxisDirection.up),
SingleActivator(
LogicalKeyboardKey.arrowDown,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(direction: AxisDirection.down),
SingleActivator(
LogicalKeyboardKey.pageUp,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(
direction: AxisDirection.up, type: ScrollIncrementType.page),
SingleActivator(
LogicalKeyboardKey.pageDown,
control: !isDesktopMacOS,
meta: isDesktopMacOS,
): const ScrollIntent(
direction: AxisDirection.down,
type: ScrollIncrementType.page),
},
),
child: Actions(
actions: mergeMaps<Type, Action<Intent>>(_actions, {
...?widget.configurations.customActions,
Expand Down

0 comments on commit 4c04fcf

Please sign in to comment.