Skip to content

Commit 0a2d839

Browse files
committed
Refactored shortcut settings
1 parent 35cc295 commit 0a2d839

File tree

3 files changed

+37
-58
lines changed

3 files changed

+37
-58
lines changed

src/data/defaultSettings.yml

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,27 @@ editor:
1212

1313
# Keyboard shortcuts (see https://craig.is/killing/mice)
1414
shortcuts:
15-
-
16-
keys: mod+s
17-
method: sync
18-
-
19-
keys: mod+shift+b
20-
method: bold
21-
-
22-
keys: mod+shift+i
23-
method: italic
24-
-
25-
keys: mod+shift+l
26-
method: link
27-
-
28-
keys: mod+shift+l
29-
method: link
30-
-
31-
keys: mod+shift+q
32-
method: quote
33-
-
34-
keys: mod+shift+k
35-
method: code
36-
-
37-
keys: mod+shift+g
38-
method: image
39-
-
40-
keys: mod+shift+o
41-
method: olist
42-
-
43-
keys: mod+shift+o
44-
method: olist
45-
-
46-
keys: mod+shift+u
47-
method: ulist
48-
-
49-
keys: mod+shift+h
50-
method: heading
51-
-
52-
keys: mod+shift+r
53-
method: hr
54-
-
55-
keys: = = > space
56-
method: expand
57-
params:
58-
- '==> '
59-
- ''
60-
-
61-
keys: < = = space
62-
method: expand
63-
params:
64-
- '<== '
65-
- ''
15+
mod+s: sync
16+
mod+shift+b: bold
17+
mod+shift+i: italic
18+
mod+shift+l: link
19+
mod+shift+q: quote
20+
mod+shift+k: code
21+
mod+shift+g: image
22+
mod+shift+o: olist
23+
mod+shift+u: ulist
24+
mod+shift+h: heading
25+
mod+shift+r: hr
26+
'= = > space':
27+
method: expand
28+
params:
29+
- '==> '
30+
- ''
31+
'< = = space':
32+
method: expand
33+
params:
34+
- '<== '
35+
- ''
6636

6737
# Default content for new files
6838
newFileContent: |

src/services/optional/shortcuts.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const methods = {
3131
return true;
3232
},
3333
expand(param1, param2) {
34-
const text = param1 && `${param1}`;
35-
const replacement = param2 && `${param2}`;
34+
const text = `${param1 || ''}`;
35+
const replacement = `${param2 || ''}`;
3636
if (text && replacement) {
3737
setTimeout(() => {
3838
const selectionMgr = editorEngineSvc.clEditor.selectionMgr;
@@ -58,15 +58,20 @@ store.watch(
5858
Mousetrap.reset();
5959

6060
const shortcuts = computedSettings.shortcuts;
61-
shortcuts.forEach((shortcut) => {
62-
if (shortcut.keys) {
63-
const method = shortcut.method || shortcut;
61+
Object.keys(shortcuts).forEach((key) => {
62+
const shortcut = shortcuts[key];
63+
if (shortcut) {
64+
const method = `${shortcut.method || shortcut}`;
6465
let params = shortcut.params || [];
6566
if (!Array.isArray(params)) {
6667
params = [params];
6768
}
6869
if (Object.prototype.hasOwnProperty.call(methods, method)) {
69-
Mousetrap.bind(`${shortcut.keys}`, () => !methods[method].apply(null, params));
70+
try {
71+
Mousetrap.bind(`${key}`, () => !methods[method].apply(null, params));
72+
} catch (e) {
73+
// Ignore
74+
}
7075
}
7176
}
7277
});

src/store/modules/data.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ module.getters.computedSettings = (state, getters) => {
8888
return opt;
8989
}
9090
Object.keys(obj).forEach((key) => {
91-
obj[key] = override(obj[key], opt[key]);
91+
if (key === 'shortcuts') {
92+
obj[key] = Object.assign(obj[key], opt[key]);
93+
} else {
94+
obj[key] = override(obj[key], opt[key]);
95+
}
9296
});
9397
return obj;
9498
};

0 commit comments

Comments
 (0)