diff --git a/src/js/editor/key-commands.ts b/src/js/editor/key-commands.ts index 14bd5d6f..6565b1d2 100644 --- a/src/js/editor/key-commands.ts +++ b/src/js/editor/key-commands.ts @@ -46,121 +46,130 @@ function deleteToEndOfSection(editor: Editor) { }) } -export const DEFAULT_KEY_COMMANDS: KeyCommand[] = [ +const MAC_KEY_COMMANDS: KeyCommand[] = [ { str: 'META+B', + name: 'default-bold', run(editor) { editor.toggleMarkup('strong') }, }, { - str: 'CTRL+B', + str: 'META+I', + name: 'default-italic', run(editor) { - editor.toggleMarkup('strong') + editor.toggleMarkup('em') }, }, { - str: 'META+I', + str: 'META+U', + name: 'default-underline', run(editor) { - editor.toggleMarkup('em') + editor.toggleMarkup('u') }, }, { - str: 'CTRL+I', + str: 'META+K', + name: 'default-link', run(editor) { - editor.toggleMarkup('em') + return toggleLink(editor) }, }, { - str: 'META+U', + str: 'META+A', + name: 'default-select-all', run(editor) { - editor.toggleMarkup('u') + selectAll(editor) }, }, { - str: 'CTRL+U', + str: 'CTRL+A', + name: 'default-goto-line-start', run(editor) { - editor.toggleMarkup('u') + gotoStartOfLine(editor) }, }, { - str: 'CTRL+K', + str: 'CTRL+E', + name: 'default-goto-line-end', run(editor) { - if (Browser.isMac()) { - return deleteToEndOfSection(editor) - } else if (Browser.isWin()) { - return toggleLink(editor) - } + gotoEndOfLine(editor) }, }, { - str: 'CTRL+A', + str: 'META+Z', + name: 'default-undo', run(editor) { - if (Browser.isMac()) { - gotoStartOfLine(editor) - } else { - selectAll(editor) - } + editor.run(postEditor => postEditor.undoLastChange()) }, }, { - str: 'META+A', + str: 'META+SHIFT+Z', + name: 'default-redo', run(editor) { - if (Browser.isMac()) { - selectAll(editor) - } + editor.run(postEditor => postEditor.redoLastChange()) }, }, { - str: 'CTRL+E', + str: 'CTRL+K', + name: 'default-delete-line', run(editor) { - if (Browser.isMac()) { - gotoEndOfLine(editor) - } + return deleteToEndOfSection(editor) }, }, +] +const WINDOWS_ETC_KEY_COMMANDS: KeyCommand[] = [ { - str: 'META+K', + str: 'CTRL+B', + name: 'default-bold', run(editor) { - return toggleLink(editor) + editor.toggleMarkup('strong') }, }, { - str: 'META+Z', + str: 'CTRL+I', + name: 'default-italic', run(editor) { - editor.run(postEditor => { - postEditor.undoLastChange() - }) + editor.toggleMarkup('em') }, }, { - str: 'META+SHIFT+Z', + str: 'CTRL+U', + name: 'default-underline', run(editor) { - editor.run(postEditor => { - postEditor.redoLastChange() - }) + editor.toggleMarkup('u') + }, + }, + { + str: 'CTRL+K', + name: 'default-link', + run(editor) { + return toggleLink(editor) + }, + }, + { + str: 'CTRL+A', + name: 'default-select-all', + run(editor) { + selectAll(editor) }, }, { str: 'CTRL+Z', + name: 'default-undo', run(editor) { - if (Browser.isMac()) { - return false - } editor.run(postEditor => postEditor.undoLastChange()) }, }, { str: 'CTRL+SHIFT+Z', + name: 'default-redo', run(editor) { - if (Browser.isMac()) { - return false - } editor.run(postEditor => postEditor.redoLastChange()) }, }, ] - +export const DEFAULT_KEY_COMMANDS = (Browser.isMac() && MAC_KEY_COMMANDS) || WINDOWS_ETC_KEY_COMMANDS function modifierNamesToMask(modiferNames: string[]) { let defaultVal = 0 return reduce( diff --git a/tests/acceptance/editor-key-commands-test.js b/tests/acceptance/editor-key-commands-test.js index 7084e050..d1d93f95 100644 --- a/tests/acceptance/editor-key-commands-test.js +++ b/tests/acceptance/editor-key-commands-test.js @@ -122,47 +122,53 @@ function testStatefulCommand({modifierName, key, command, markupName}) { }); } -testStatefulCommand({ - modifierName: 'META', - key: 'B', - command: 'command-B', - markupName: 'strong' -}); - -testStatefulCommand({ - modifierName: 'CTRL', - key: 'B', - command: 'ctrl-B', - markupName: 'strong' -}); - -testStatefulCommand({ - modifierName: 'META', - key: 'I', - command: 'command-I', - markupName: 'em' -}); - -testStatefulCommand({ - modifierName: 'CTRL', - key: 'I', - command: 'ctrl-I', - markupName: 'em' -}); +if (Browser.isMac()) { + testStatefulCommand({ + modifierName: 'META', + key: 'B', + command: 'command-B', + markupName: 'strong' + }); +} else { + testStatefulCommand({ + modifierName: 'CTRL', + key: 'B', + command: 'ctrl-B', + markupName: 'strong' + }); +} -testStatefulCommand({ - modifierName: 'META', - key: 'U', - command: 'command-U', - markupName: 'u' -}); +if (Browser.isMac()) { + testStatefulCommand({ + modifierName: 'META', + key: 'I', + command: 'command-I', + markupName: 'em' + }); +} else { + testStatefulCommand({ + modifierName: 'CTRL', + key: 'I', + command: 'ctrl-I', + markupName: 'em' + }); +} -testStatefulCommand({ - modifierName: 'CTRL', - key: 'U', - command: 'ctrl-U', - markupName: 'u' -}); +if (Browser.isMac()) { + testStatefulCommand({ + modifierName: 'META', + key: 'U', + command: 'command-U', + markupName: 'u' + }); +} else { + testStatefulCommand({ + modifierName: 'CTRL', + key: 'U', + command: 'ctrl-U', + markupName: 'u' + }); +} if (Browser.isMac()) { test(`[Mac] ctrl-k clears to the end of a line`, (assert) => {