Skip to content

Commit b6e3410

Browse files
committed
use mod instead of opaque meta/ctrl to signal meta or ctrl
1 parent 65e81ac commit b6e3410

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

components/editor/plugins/core/shortcuts.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,75 +11,75 @@ import { SUBMIT_FORMIK_COMMAND } from '@/components/editor/plugins/core/formik'
1111

1212
export const SHORTCUTS = {
1313
link: {
14-
key: 'meta+KeyK',
14+
key: 'mod+KeyK',
1515
handler: (editor) => editor.dispatchCommand(SN_TOGGLE_LINK_COMMAND)
1616
},
1717
bold: {
18-
key: 'meta+KeyB',
18+
key: 'mod+KeyB',
1919
handler: (editor) => editor.dispatchCommand(SN_FORMAT_COMMAND, 'bold')
2020
},
2121
italic: {
22-
key: 'meta+KeyI',
22+
key: 'mod+KeyI',
2323
handler: (editor) => editor.dispatchCommand(SN_FORMAT_COMMAND, 'italic')
2424
},
2525
quote: {
2626
key: 'control+shift+KeyQ',
2727
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'quote')
2828
},
2929
inlineCode: {
30-
key: 'meta+KeyE',
30+
key: 'mod+KeyE',
3131
handler: (editor) => editor.dispatchCommand(SN_FORMAT_COMMAND, 'code')
3232
},
3333
superscript: {
34-
key: 'meta+Period',
34+
key: 'mod+Period',
3535
handler: (editor) => editor.dispatchCommand(SN_FORMAT_COMMAND, 'superscript')
3636
},
3737
subscript: {
38-
key: 'meta+Comma',
38+
key: 'mod+Comma',
3939
handler: (editor) => editor.dispatchCommand(SN_FORMAT_COMMAND, 'subscript')
4040
},
4141
strikethrough: {
42-
key: 'meta+shift+KeyX',
42+
key: 'mod+shift+KeyX',
4343
handler: (editor) => editor.dispatchCommand(SN_FORMAT_COMMAND, 'strikethrough')
4444
},
4545
h1: {
46-
key: 'meta+alt+Digit1',
46+
key: 'mod+alt+Digit1',
4747
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'h1')
4848
},
4949
h2: {
50-
key: 'meta+alt+Digit2',
50+
key: 'mod+alt+Digit2',
5151
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'h2')
5252
},
5353
h3: {
54-
key: 'meta+alt+Digit3',
54+
key: 'mod+alt+Digit3',
5555
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'h3')
5656
},
5757
numberedList: {
58-
key: 'meta+shift+Digit7',
58+
key: 'mod+shift+Digit7',
5959
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'number')
6060
},
6161
bulletList: {
62-
key: 'meta+shift+Digit8',
62+
key: 'mod+shift+Digit8',
6363
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'bullet')
6464
},
6565
check: {
66-
key: 'meta+shift+Digit9',
66+
key: 'mod+shift+Digit9',
6767
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'check')
6868
},
6969
codeblock: {
70-
key: 'meta+alt+KeyC',
70+
key: 'mod+alt+KeyC',
7171
handler: (editor) => editor.dispatchCommand(SN_FORMAT_BLOCK_COMMAND, 'code')
7272
},
7373
upload: {
74-
key: 'meta+KeyU',
74+
key: 'mod+KeyU',
7575
handler: (editor) => editor.dispatchCommand(SN_UPLOAD_FILES_COMMAND)
7676
},
7777
preview: {
78-
key: 'meta+KeyP',
78+
key: 'mod+KeyP',
7979
handler: (editor) => editor.dispatchCommand(TOGGLE_PREVIEW_COMMAND, editor)
8080
},
8181
submit: {
82-
key: 'meta+Enter',
82+
key: 'mod+Enter',
8383
handler: (editor) => editor.dispatchCommand(SUBMIT_FORMIK_COMMAND)
8484
}
8585
}
@@ -96,16 +96,19 @@ export default function ShortcutsPlugin ({ shortcuts = SHORTCUTS }) {
9696
if (!key) continue
9797

9898
const parts = key.toLowerCase().split('+')
99-
const needsMeta = parts.includes('meta') || parts.includes('control')
99+
const needsMod = parts.includes('mod')
100+
const needsControl = parts.includes('control')
100101
const needsShift = parts.includes('shift')
101102
const needsAlt = parts.includes('alt')
102103
const targetCode = parts[parts.length - 1]
103104

104-
const metaOrCtrl = e.metaKey || e.ctrlKey
105+
const hasMod = e.metaKey || e.ctrlKey
106+
const hasControl = e.ctrlKey
105107
const hasShift = e.shiftKey
106108
const hasAlt = e.altKey
107109

108-
if (needsMeta && !metaOrCtrl) continue
110+
if (needsMod && !hasMod) continue
111+
if (needsControl && !hasControl) continue
109112
if (needsShift !== hasShift) continue
110113
if (needsAlt !== hasAlt) continue
111114

@@ -128,7 +131,7 @@ export default function ShortcutsPlugin ({ shortcuts = SHORTCUTS }) {
128131

129132
// modifier key display mapping
130133
const MODIFIER_DISPLAY = {
131-
meta: IS_APPLE ? '⌘' : 'ctrl',
134+
mod: IS_APPLE ? '⌘' : 'ctrl',
132135
control: IS_APPLE ? '⌃' : 'ctrl',
133136
alt: IS_APPLE ? '⌥' : 'alt'
134137
}
@@ -141,7 +144,7 @@ function codeToDisplay (code) {
141144
return special[code] || code
142145
}
143146

144-
// format a shortcut key string for display (e.g., 'meta+shift+Digit1' -> '⌘+shift+1')
147+
// format a shortcut key string for display (e.g., 'mod+shift+Digit1' -> '⌘+shift+1')
145148
export function formatShortcut (key) {
146149
if (!key) return ''
147150
const parts = key.split('+')

0 commit comments

Comments
 (0)