Refactored shortcut settings
This commit is contained in:
parent
35cc2952fb
commit
0a2d8396d6
@ -12,53 +12,23 @@ editor:
|
||||
|
||||
# Keyboard shortcuts (see https://craig.is/killing/mice)
|
||||
shortcuts:
|
||||
-
|
||||
keys: mod+s
|
||||
method: sync
|
||||
-
|
||||
keys: mod+shift+b
|
||||
method: bold
|
||||
-
|
||||
keys: mod+shift+i
|
||||
method: italic
|
||||
-
|
||||
keys: mod+shift+l
|
||||
method: link
|
||||
-
|
||||
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
|
||||
mod+s: sync
|
||||
mod+shift+b: bold
|
||||
mod+shift+i: italic
|
||||
mod+shift+l: link
|
||||
mod+shift+q: quote
|
||||
mod+shift+k: code
|
||||
mod+shift+g: image
|
||||
mod+shift+o: olist
|
||||
mod+shift+u: ulist
|
||||
mod+shift+h: heading
|
||||
mod+shift+r: hr
|
||||
'= = > space':
|
||||
method: expand
|
||||
params:
|
||||
- '==> '
|
||||
- '⇒ '
|
||||
-
|
||||
keys: < = = space
|
||||
'< = = space':
|
||||
method: expand
|
||||
params:
|
||||
- '<== '
|
||||
|
@ -31,8 +31,8 @@ const methods = {
|
||||
return true;
|
||||
},
|
||||
expand(param1, param2) {
|
||||
const text = param1 && `${param1}`;
|
||||
const replacement = param2 && `${param2}`;
|
||||
const text = `${param1 || ''}`;
|
||||
const replacement = `${param2 || ''}`;
|
||||
if (text && replacement) {
|
||||
setTimeout(() => {
|
||||
const selectionMgr = editorEngineSvc.clEditor.selectionMgr;
|
||||
@ -58,15 +58,20 @@ store.watch(
|
||||
Mousetrap.reset();
|
||||
|
||||
const shortcuts = computedSettings.shortcuts;
|
||||
shortcuts.forEach((shortcut) => {
|
||||
if (shortcut.keys) {
|
||||
const method = shortcut.method || shortcut;
|
||||
Object.keys(shortcuts).forEach((key) => {
|
||||
const shortcut = shortcuts[key];
|
||||
if (shortcut) {
|
||||
const method = `${shortcut.method || shortcut}`;
|
||||
let params = shortcut.params || [];
|
||||
if (!Array.isArray(params)) {
|
||||
params = [params];
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -88,7 +88,11 @@ module.getters.computedSettings = (state, getters) => {
|
||||
return opt;
|
||||
}
|
||||
Object.keys(obj).forEach((key) => {
|
||||
if (key === 'shortcuts') {
|
||||
obj[key] = Object.assign(obj[key], opt[key]);
|
||||
} else {
|
||||
obj[key] = override(obj[key], opt[key]);
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user