Swap order of shortcut map merging so that customShortcuts are added first and override existing duplicate trigger shortcuts by absorbing the input first (#2089)

Co-authored-by: ryanscott0515 <ryanscott0515@gmail.com>
pull/2093/head v10.1.7
DeveloperBiz 8 months ago committed by GitHub
parent 23f66b38ae
commit 4c04fcf90a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 367
      lib/src/editor/raw_editor/raw_editor_state.dart

@ -533,187 +533,192 @@ class QuillRawEditorState extends EditorState
child: QuillStyles( child: QuillStyles(
data: _styles!, data: _styles!,
child: Shortcuts( child: Shortcuts(
shortcuts: mergeMaps<ShortcutActivator, Intent>({ /// Merge with widget.configurations.customShortcuts
// shortcuts added for Desktop platforms. /// first to allow user's defined shortcuts to take
const SingleActivator( /// priority when activation triggers are the same
LogicalKeyboardKey.escape, shortcuts: mergeMaps<ShortcutActivator, Intent>(
): const HideSelectionToolbarIntent(), {...?widget.configurations.customShortcuts},
SingleActivator( {
LogicalKeyboardKey.keyZ, // shortcuts added for Desktop platforms.
control: !isDesktopMacOS, const SingleActivator(
meta: isDesktopMacOS, LogicalKeyboardKey.escape,
): const UndoTextIntent(SelectionChangedCause.keyboard), ): const HideSelectionToolbarIntent(),
SingleActivator( SingleActivator(
LogicalKeyboardKey.keyY, LogicalKeyboardKey.keyZ,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const RedoTextIntent(SelectionChangedCause.keyboard), ): const UndoTextIntent(SelectionChangedCause.keyboard),
SingleActivator(
// Selection formatting. LogicalKeyboardKey.keyY,
SingleActivator( control: !isDesktopMacOS,
LogicalKeyboardKey.keyB, meta: isDesktopMacOS,
control: !isDesktopMacOS, ): const RedoTextIntent(SelectionChangedCause.keyboard),
meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.bold), // Selection formatting.
SingleActivator( SingleActivator(
LogicalKeyboardKey.keyU, LogicalKeyboardKey.keyB,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.underline), ): const ToggleTextStyleIntent(Attribute.bold),
SingleActivator( SingleActivator(
LogicalKeyboardKey.keyI, LogicalKeyboardKey.keyU,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const ToggleTextStyleIntent(Attribute.italic), ): const ToggleTextStyleIntent(Attribute.underline),
SingleActivator( SingleActivator(
LogicalKeyboardKey.keyS, LogicalKeyboardKey.keyI,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
shift: true, ): const ToggleTextStyleIntent(Attribute.italic),
): const ToggleTextStyleIntent(Attribute.strikeThrough), SingleActivator(
SingleActivator( LogicalKeyboardKey.keyS,
LogicalKeyboardKey.backquote, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, shift: true,
): const ToggleTextStyleIntent(Attribute.inlineCode), ): const ToggleTextStyleIntent(Attribute.strikeThrough),
SingleActivator( SingleActivator(
LogicalKeyboardKey.tilde, LogicalKeyboardKey.backquote,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
shift: true, ): const ToggleTextStyleIntent(Attribute.inlineCode),
): const ToggleTextStyleIntent(Attribute.codeBlock), SingleActivator(
SingleActivator( LogicalKeyboardKey.tilde,
LogicalKeyboardKey.keyB, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, shift: true,
shift: true, ): const ToggleTextStyleIntent(Attribute.codeBlock),
): const ToggleTextStyleIntent(Attribute.blockQuote), SingleActivator(
SingleActivator( LogicalKeyboardKey.keyB,
LogicalKeyboardKey.keyK, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, shift: true,
): const QuillEditorApplyLinkIntent(), ): const ToggleTextStyleIntent(Attribute.blockQuote),
SingleActivator(
// Lists LogicalKeyboardKey.keyK,
SingleActivator( control: !isDesktopMacOS,
LogicalKeyboardKey.keyL, meta: isDesktopMacOS,
control: !isDesktopMacOS, ): const QuillEditorApplyLinkIntent(),
meta: isDesktopMacOS,
shift: true, // Lists
): const ToggleTextStyleIntent(Attribute.ul), SingleActivator(
SingleActivator( LogicalKeyboardKey.keyL,
LogicalKeyboardKey.keyO, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, shift: true,
shift: true, ): const ToggleTextStyleIntent(Attribute.ul),
): const ToggleTextStyleIntent(Attribute.ol), SingleActivator(
SingleActivator( LogicalKeyboardKey.keyO,
LogicalKeyboardKey.keyC, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, shift: true,
shift: true, ): const ToggleTextStyleIntent(Attribute.ol),
): const QuillEditorApplyCheckListIntent(), SingleActivator(
LogicalKeyboardKey.keyC,
// Indents control: !isDesktopMacOS,
SingleActivator( meta: isDesktopMacOS,
LogicalKeyboardKey.keyM, shift: true,
control: !isDesktopMacOS, ): const QuillEditorApplyCheckListIntent(),
meta: isDesktopMacOS,
): const IndentSelectionIntent(true), // Indents
SingleActivator( SingleActivator(
LogicalKeyboardKey.keyM, LogicalKeyboardKey.keyM,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
shift: true, ): const IndentSelectionIntent(true),
): const IndentSelectionIntent(false), SingleActivator(
LogicalKeyboardKey.keyM,
// Headers control: !isDesktopMacOS,
SingleActivator( meta: isDesktopMacOS,
LogicalKeyboardKey.digit1, shift: true,
control: !isDesktopMacOS, ): const IndentSelectionIntent(false),
meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h1), // Headers
SingleActivator( SingleActivator(
LogicalKeyboardKey.digit2, LogicalKeyboardKey.digit1,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h2), ): const QuillEditorApplyHeaderIntent(Attribute.h1),
SingleActivator( SingleActivator(
LogicalKeyboardKey.digit3, LogicalKeyboardKey.digit2,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h3), ): const QuillEditorApplyHeaderIntent(Attribute.h2),
SingleActivator( SingleActivator(
LogicalKeyboardKey.digit4, LogicalKeyboardKey.digit3,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h4), ): const QuillEditorApplyHeaderIntent(Attribute.h3),
SingleActivator( SingleActivator(
LogicalKeyboardKey.digit5, LogicalKeyboardKey.digit4,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h5), ): const QuillEditorApplyHeaderIntent(Attribute.h4),
SingleActivator( SingleActivator(
LogicalKeyboardKey.digit6, LogicalKeyboardKey.digit5,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.h6), ): const QuillEditorApplyHeaderIntent(Attribute.h5),
SingleActivator( SingleActivator(
LogicalKeyboardKey.digit0, LogicalKeyboardKey.digit6,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const QuillEditorApplyHeaderIntent(Attribute.header), ): const QuillEditorApplyHeaderIntent(Attribute.h6),
SingleActivator(
SingleActivator( LogicalKeyboardKey.digit0,
LogicalKeyboardKey.keyG, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, ): const QuillEditorApplyHeaderIntent(Attribute.header),
): const QuillEditorInsertEmbedIntent(Attribute.image),
SingleActivator(
SingleActivator( LogicalKeyboardKey.keyG,
LogicalKeyboardKey.keyF, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, ): const QuillEditorInsertEmbedIntent(Attribute.image),
): const OpenSearchIntent(),
SingleActivator(
// Navigate to the start or end of the document LogicalKeyboardKey.keyF,
SingleActivator( control: !isDesktopMacOS,
LogicalKeyboardKey.home, meta: isDesktopMacOS,
control: !isDesktopMacOS, ): const OpenSearchIntent(),
meta: isDesktopMacOS,
): const ScrollToDocumentBoundaryIntent(forward: false), // Navigate to the start or end of the document
SingleActivator( SingleActivator(
LogicalKeyboardKey.end, LogicalKeyboardKey.home,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const ScrollToDocumentBoundaryIntent(forward: true), ): const ScrollToDocumentBoundaryIntent(forward: false),
SingleActivator(
// Arrow key scrolling LogicalKeyboardKey.end,
SingleActivator( control: !isDesktopMacOS,
LogicalKeyboardKey.arrowUp, meta: isDesktopMacOS,
control: !isDesktopMacOS, ): const ScrollToDocumentBoundaryIntent(forward: true),
meta: isDesktopMacOS,
): const ScrollIntent(direction: AxisDirection.up), // Arrow key scrolling
SingleActivator( SingleActivator(
LogicalKeyboardKey.arrowDown, LogicalKeyboardKey.arrowUp,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const ScrollIntent(direction: AxisDirection.down), ): const ScrollIntent(direction: AxisDirection.up),
SingleActivator( SingleActivator(
LogicalKeyboardKey.pageUp, LogicalKeyboardKey.arrowDown,
control: !isDesktopMacOS, control: !isDesktopMacOS,
meta: isDesktopMacOS, meta: isDesktopMacOS,
): const ScrollIntent( ): const ScrollIntent(direction: AxisDirection.down),
direction: AxisDirection.up, type: ScrollIncrementType.page), SingleActivator(
SingleActivator( LogicalKeyboardKey.pageUp,
LogicalKeyboardKey.pageDown, control: !isDesktopMacOS,
control: !isDesktopMacOS, meta: isDesktopMacOS,
meta: isDesktopMacOS, ): const ScrollIntent(
): const ScrollIntent( direction: AxisDirection.up, type: ScrollIncrementType.page),
direction: AxisDirection.down, type: ScrollIncrementType.page), SingleActivator(
}, { LogicalKeyboardKey.pageDown,
...?widget.configurations.customShortcuts control: !isDesktopMacOS,
}), meta: isDesktopMacOS,
): const ScrollIntent(
direction: AxisDirection.down,
type: ScrollIncrementType.page),
},
),
child: Actions( child: Actions(
actions: mergeMaps<Type, Action<Intent>>(_actions, { actions: mergeMaps<Type, Action<Intent>>(_actions, {
...?widget.configurations.customActions, ...?widget.configurations.customActions,

Loading…
Cancel
Save