From 069865efba9662156d174d92582e1870cfe0ce51 Mon Sep 17 00:00:00 2001 From: Henning Pohlmeyer Date: Mon, 27 Nov 2017 00:04:42 +0100 Subject: [PATCH 1/2] Split shortcuts by platform and name them --- src/js/editor/key-commands.ts | 105 ++++++++++--------- tests/acceptance/editor-key-commands-test.js | 84 ++++++++------- 2 files changed, 102 insertions(+), 87 deletions(-) diff --git a/src/js/editor/key-commands.ts b/src/js/editor/key-commands.ts index 14bd5d6f7..6565b1d2f 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 7084e050a..d1d93f951 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) => { From 4bc718a26285b8fcef047f4426d3b042f4732cde Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Mon, 18 Sep 2023 00:44:12 -0400 Subject: [PATCH 2/2] Use the right keyboard shortcut for Undo/Redo tests --- tests/acceptance/editor-undo-redo-test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/editor-undo-redo-test.js b/tests/acceptance/editor-undo-redo-test.js index 6c1a5b0fc..9fc7241a1 100644 --- a/tests/acceptance/editor-undo-redo-test.js +++ b/tests/acceptance/editor-undo-redo-test.js @@ -1,5 +1,6 @@ import { MODIFIERS } from 'mobiledoc-kit/utils/key'; import Helpers from '../test-helpers'; +import Browser from 'mobiledoc-kit/utils/browser'; const { module, test } = Helpers; @@ -8,11 +9,11 @@ const undoBlockTimeout = 2000; let editor, editorElement, oldDateNow; function undo(editor) { - Helpers.dom.triggerKeyCommand(editor, 'Z', [MODIFIERS.META]); + Helpers.dom.triggerKeyCommand(editor, 'Z', [Browser.isMac() ? MODIFIERS.META : MODIFIERS.CTRL]); } function redo(editor) { - Helpers.dom.triggerKeyCommand(editor, 'Z', [MODIFIERS.META, MODIFIERS.SHIFT]); + Helpers.dom.triggerKeyCommand(editor, 'Z', [Browser.isMac() ? MODIFIERS.META : MODIFIERS.CTRL, MODIFIERS.SHIFT]); } module('Acceptance: Editor: Undo/Redo', {