Skip to content

Commit 93ebe4f

Browse files
hpohlmeyerlukemelia
authored andcommitted
Split shortcuts by platform and name them
1 parent 942bc72 commit 93ebe4f

File tree

2 files changed

+121
-103
lines changed

2 files changed

+121
-103
lines changed

src/js/editor/key-commands.ts

Lines changed: 76 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -46,120 +46,132 @@ function deleteToEndOfSection(editor: Editor) {
4646
})
4747
}
4848

49-
export const DEFAULT_KEY_COMMANDS: KeyCommand[] = [
49+
const MAC_KEY_COMMANDS: KeyCommand[] = [
5050
{
5151
str: 'META+B',
52+
name: 'default-bold',
5253
run(editor) {
53-
editor.toggleMarkup('strong')
54-
},
55-
},
56-
{
57-
str: 'CTRL+B',
58-
run(editor) {
59-
editor.toggleMarkup('strong')
60-
},
54+
editor.toggleMarkup('strong');
55+
}
6156
},
6257
{
6358
str: 'META+I',
59+
name: 'default-italic',
6460
run(editor) {
6561
editor.toggleMarkup('em')
6662
},
6763
},
6864
{
69-
str: 'CTRL+I',
65+
str: 'META+U',
66+
name: 'default-underline',
7067
run(editor) {
71-
editor.toggleMarkup('em')
68+
editor.toggleMarkup('u')
7269
},
7370
},
7471
{
75-
str: 'META+U',
72+
str: 'META+K',
73+
name: 'default-link',
7674
run(editor) {
77-
editor.toggleMarkup('u')
75+
return toggleLink(editor)
7876
},
7977
},
8078
{
81-
str: 'CTRL+U',
79+
str: 'META+A',
80+
name: 'default-select-all',
8281
run(editor) {
83-
editor.toggleMarkup('u')
84-
},
82+
selectAll(editor);
83+
}
84+
},
85+
{
86+
str: 'CTRL+A',
87+
name: 'default-goto-line-start',
88+
run(editor) {
89+
gotoStartOfLine(editor);
90+
}
8591
},
8692
{
87-
str: 'CTRL+K',
93+
str: 'CTRL+E',
94+
name: 'default-goto-line-end',
8895
run(editor) {
89-
if (Browser.isMac()) {
90-
return deleteToEndOfSection(editor)
91-
} else if (Browser.isWin()) {
92-
return toggleLink(editor)
93-
}
94-
},
96+
gotoEndOfLine(editor);
97+
}
9598
},
9699
{
97-
str: 'CTRL+A',
100+
str: 'META+Z',
101+
name: 'default-undo',
98102
run(editor) {
99-
if (Browser.isMac()) {
100-
gotoStartOfLine(editor)
101-
} else {
102-
selectAll(editor)
103-
}
104-
},
103+
editor.run(postEditor => postEditor.undoLastChange());
104+
}
105105
},
106106
{
107-
str: 'META+A',
107+
str: 'META+SHIFT+Z',
108+
name: 'default-redo',
108109
run(editor) {
109-
if (Browser.isMac()) {
110-
selectAll(editor)
111-
}
112-
},
110+
editor.run(postEditor => postEditor.redoLastChange());
111+
}
113112
},
114113
{
115-
str: 'CTRL+E',
114+
str: 'CTRL+K',
115+
name: 'default-delete-line',
116116
run(editor) {
117-
if (Browser.isMac()) {
118-
gotoEndOfLine(editor)
119-
}
120-
},
117+
return deleteToEndOfSection(editor);
118+
}
119+
}
120+
];
121+
122+
const WINDOWS_ETC_KEY_COMMANDS: KeyCommand[] = [
123+
{
124+
str: 'CTRL+B',
125+
name: 'default-bold',
126+
run(editor) {
127+
editor.toggleMarkup('strong');
128+
}
121129
},
122130
{
123-
str: 'META+K',
131+
str: 'CTRL+I',
132+
name: 'default-italic',
124133
run(editor) {
125-
return toggleLink(editor)
134+
editor.toggleMarkup('em')
126135
},
127136
},
128137
{
129-
str: 'META+Z',
138+
str: 'CTRL+U',
139+
name: 'default-underline',
130140
run(editor) {
131-
editor.run(postEditor => {
132-
postEditor.undoLastChange()
133-
})
141+
editor.toggleMarkup('u')
134142
},
135143
},
136144
{
137-
str: 'META+SHIFT+Z',
145+
str: 'CTRL+K',
146+
name: 'default-link',
138147
run(editor) {
139-
editor.run(postEditor => {
140-
postEditor.redoLastChange()
141-
})
142-
},
148+
return toggleLink(editor);
149+
}
143150
},
144151
{
145-
str: 'CTRL+Z',
152+
str: 'CTRL+A',
153+
name: 'default-select-all',
146154
run(editor) {
147-
if (Browser.isMac()) {
148-
return false
149-
}
150-
editor.run(postEditor => postEditor.undoLastChange())
151-
},
155+
selectAll(editor);
156+
}
152157
},
153158
{
159+
str: 'CTRL+Z',
160+
name: 'default-undo',
161+
run(editor) {
162+
editor.run(postEditor => postEditor.undoLastChange());
163+
}
164+
}, {
154165
str: 'CTRL+SHIFT+Z',
166+
name: 'default-redo',
155167
run(editor) {
156-
if (Browser.isMac()) {
157-
return false
158-
}
159-
editor.run(postEditor => postEditor.redoLastChange())
160-
},
161-
},
162-
]
168+
editor.run(postEditor => postEditor.redoLastChange());
169+
}
170+
}
171+
];
172+
173+
export const DEFAULT_KEY_COMMANDS = (Browser.isMac() && MAC_KEY_COMMANDS)
174+
|| WINDOWS_ETC_KEY_COMMANDS;
163175

164176
function modifierNamesToMask(modiferNames: string[]) {
165177
let defaultVal = 0

tests/acceptance/editor-key-commands-test.js

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -122,47 +122,53 @@ function testStatefulCommand({modifierName, key, command, markupName}) {
122122
});
123123
}
124124

125-
testStatefulCommand({
126-
modifierName: 'META',
127-
key: 'B',
128-
command: 'command-B',
129-
markupName: 'strong'
130-
});
131-
132-
testStatefulCommand({
133-
modifierName: 'CTRL',
134-
key: 'B',
135-
command: 'ctrl-B',
136-
markupName: 'strong'
137-
});
138-
139-
testStatefulCommand({
140-
modifierName: 'META',
141-
key: 'I',
142-
command: 'command-I',
143-
markupName: 'em'
144-
});
145-
146-
testStatefulCommand({
147-
modifierName: 'CTRL',
148-
key: 'I',
149-
command: 'ctrl-I',
150-
markupName: 'em'
151-
});
125+
if (Browser.isMac()) {
126+
testStatefulCommand({
127+
modifierName: 'META',
128+
key: 'B',
129+
command: 'command-B',
130+
markupName: 'strong'
131+
});
132+
} else {
133+
testStatefulCommand({
134+
modifierName: 'CTRL',
135+
key: 'B',
136+
command: 'ctrl-B',
137+
markupName: 'strong'
138+
});
139+
}
152140

153-
testStatefulCommand({
154-
modifierName: 'META',
155-
key: 'U',
156-
command: 'command-U',
157-
markupName: 'u'
158-
});
141+
if (Browser.isMac()) {
142+
testStatefulCommand({
143+
modifierName: 'META',
144+
key: 'I',
145+
command: 'command-I',
146+
markupName: 'em'
147+
});
148+
} else {
149+
testStatefulCommand({
150+
modifierName: 'CTRL',
151+
key: 'I',
152+
command: 'ctrl-I',
153+
markupName: 'em'
154+
});
155+
}
159156

160-
testStatefulCommand({
161-
modifierName: 'CTRL',
162-
key: 'U',
163-
command: 'ctrl-U',
164-
markupName: 'u'
165-
});
157+
if (Browser.isMac()) {
158+
testStatefulCommand({
159+
modifierName: 'META',
160+
key: 'U',
161+
command: 'command-U',
162+
markupName: 'u'
163+
});
164+
} else {
165+
testStatefulCommand({
166+
modifierName: 'CTRL',
167+
key: 'U',
168+
command: 'ctrl-U',
169+
markupName: 'u'
170+
});
171+
}
166172

167173
if (Browser.isMac()) {
168174
test(`[Mac] ctrl-k clears to the end of a line`, (assert) => {

0 commit comments

Comments
 (0)