diff --git a/src/data/defaultSettings.yml b/src/data/defaultSettings.yml index 4b0c4a24..7b6ef7e6 100644 --- a/src/data/defaultSettings.yml +++ b/src/data/defaultSettings.yml @@ -12,57 +12,27 @@ 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 - method: expand - params: - - '==> ' - - '⇒ ' -- - keys: < = = space - method: expand - params: - - '<== ' - - '⇐ ' + 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: + - '==> ' + - '⇒ ' + '< = = space': + method: expand + params: + - '<== ' + - '⇐ ' # Default content for new files newFileContent: | diff --git a/src/services/optional/shortcuts.js b/src/services/optional/shortcuts.js index 579a231b..ed7beb9e 100644 --- a/src/services/optional/shortcuts.js +++ b/src/services/optional/shortcuts.js @@ -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 + } } } }); diff --git a/src/store/modules/data.js b/src/store/modules/data.js index 5c5dd25f..a50ba50b 100644 --- a/src/store/modules/data.js +++ b/src/store/modules/data.js @@ -88,7 +88,11 @@ module.getters.computedSettings = (state, getters) => { return opt; } Object.keys(obj).forEach((key) => { - obj[key] = override(obj[key], opt[key]); + if (key === 'shortcuts') { + obj[key] = Object.assign(obj[key], opt[key]); + } else { + obj[key] = override(obj[key], opt[key]); + } }); return obj; };