Refactored shortcut settings

This commit is contained in:
benweet 2017-10-05 08:18:02 +01:00
parent 35cc2952fb
commit 0a2d8396d6
3 changed files with 37 additions and 58 deletions

View File

@ -12,53 +12,23 @@ editor:
# Keyboard shortcuts (see https://craig.is/killing/mice) # Keyboard shortcuts (see https://craig.is/killing/mice)
shortcuts: shortcuts:
- mod+s: sync
keys: mod+s mod+shift+b: bold
method: sync mod+shift+i: italic
- mod+shift+l: link
keys: mod+shift+b mod+shift+q: quote
method: bold mod+shift+k: code
- mod+shift+g: image
keys: mod+shift+i mod+shift+o: olist
method: italic mod+shift+u: ulist
- mod+shift+h: heading
keys: mod+shift+l mod+shift+r: hr
method: link '= = > space':
-
keys: mod+shift+l
method: link
-
keys: mod+shift+q
method: quote
-
keys: mod+shift+k
method: code
-
keys: mod+shift+g
method: image
-
keys: mod+shift+o
method: olist
-
keys: mod+shift+o
method: olist
-
keys: mod+shift+u
method: ulist
-
keys: mod+shift+h
method: heading
-
keys: mod+shift+r
method: hr
-
keys: = = > space
method: expand method: expand
params: params:
- '==> ' - '==> '
- '⇒ ' - '⇒ '
- '< = = space':
keys: < = = space
method: expand method: expand
params: params:
- '<== ' - '<== '

View File

@ -31,8 +31,8 @@ const methods = {
return true; return true;
}, },
expand(param1, param2) { expand(param1, param2) {
const text = param1 && `${param1}`; const text = `${param1 || ''}`;
const replacement = param2 && `${param2}`; const replacement = `${param2 || ''}`;
if (text && replacement) { if (text && replacement) {
setTimeout(() => { setTimeout(() => {
const selectionMgr = editorEngineSvc.clEditor.selectionMgr; const selectionMgr = editorEngineSvc.clEditor.selectionMgr;
@ -58,15 +58,20 @@ store.watch(
Mousetrap.reset(); Mousetrap.reset();
const shortcuts = computedSettings.shortcuts; const shortcuts = computedSettings.shortcuts;
shortcuts.forEach((shortcut) => { Object.keys(shortcuts).forEach((key) => {
if (shortcut.keys) { const shortcut = shortcuts[key];
const method = shortcut.method || shortcut; if (shortcut) {
const method = `${shortcut.method || shortcut}`;
let params = shortcut.params || []; let params = shortcut.params || [];
if (!Array.isArray(params)) { if (!Array.isArray(params)) {
params = [params]; params = [params];
} }
if (Object.prototype.hasOwnProperty.call(methods, method)) { if (Object.prototype.hasOwnProperty.call(methods, method)) {
Mousetrap.bind(`${shortcut.keys}`, () => !methods[method].apply(null, params)); try {
Mousetrap.bind(`${key}`, () => !methods[method].apply(null, params));
} catch (e) {
// Ignore
}
} }
} }
}); });

View File

@ -88,7 +88,11 @@ module.getters.computedSettings = (state, getters) => {
return opt; return opt;
} }
Object.keys(obj).forEach((key) => { Object.keys(obj).forEach((key) => {
if (key === 'shortcuts') {
obj[key] = Object.assign(obj[key], opt[key]);
} else {
obj[key] = override(obj[key], opt[key]); obj[key] = override(obj[key], opt[key]);
}
}); });
return obj; return obj;
}; };