From 587134c2f8e7d0fb7f043e9791f38bfcef1be1bb Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 20 Nov 2019 23:10:41 +0100 Subject: [PATCH] separators and fixes --- .../dialogs/options/keyboard_shortcuts.js | 33 ++- .../javascripts/services/entrypoints.js | 4 +- src/services/keyboard_actions.js | 197 ++++++++++-------- 3 files changed, 138 insertions(+), 96 deletions(-) diff --git a/src/public/javascripts/dialogs/options/keyboard_shortcuts.js b/src/public/javascripts/dialogs/options/keyboard_shortcuts.js index 5120f3a87..5266eb5cc 100644 --- a/src/public/javascripts/dialogs/options/keyboard_shortcuts.js +++ b/src/public/javascripts/dialogs/options/keyboard_shortcuts.js @@ -35,17 +35,27 @@ export default class KeyboardShortcutsOptions { server.get('keyboard-actions').then(actions => { for (const action of actions) { - const $tr = $("") - .append($("").text(action.actionName)) - .append($("").append( - $(``) - .val(action.effectiveShortcuts.join(", ")) - .attr('data-keyboard-action-name', action.actionName) - .attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", ")) - ) + const $tr = $(""); + + if (action.separator) { + $tr.append( + $('') + .attr("style","background-color: var(--accented-background-color); font-weight: bold;") + .text(action.separator) ) - .append($("").text(action.defaultShortcuts.join(", "))) - .append($("").text(action.description)); + } + else { + $tr.append($("").text(action.actionName)) + .append($("").append( + $(``) + .val(action.effectiveShortcuts.join(", ")) + .attr('data-keyboard-action-name', action.actionName) + .attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", ")) + ) + ) + .append($("").text(action.defaultShortcuts.join(", "))) + .append($("").text(action.description)); + } $table.append($tr); } @@ -57,7 +67,8 @@ export default class KeyboardShortcutsOptions { const shortcuts = $input.val() .replace('+,', "+Comma") .split(",") - .map(shortcut => shortcut.replace("+Comma", "+,")); + .map(shortcut => shortcut.replace("+Comma", "+,")) + .filter(shortcut => !!shortcut); const opts = {}; opts['keyboardShortcuts' + actionName] = JSON.stringify(shortcuts); diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index 31e6ee6c5..57601c6fe 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -259,7 +259,9 @@ function setActionHandler(actionName, handler) { action.handler = handler; for (const shortcut of action.effectiveShortcuts) { - utils.bindGlobalShortcut(shortcut, handler); + if (shortcut) { + utils.bindGlobalShortcut(shortcut, handler); + } } }); } diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index e8a928348..5c4788bee 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -6,14 +6,26 @@ const log = require('./log'); const ELECTRON = "electron"; const DEFAULT_KEYBOARD_ACTIONS = [ + { + separator: "Note navigation" + }, + { + actionName: "BackInNoteHistory", + defaultShortcuts: ["Alt+Left"] + }, + { + actionName: "ForwardInNoteHistory", + defaultShortcuts: ["Alt+Right"] + }, { actionName: "JumpToNote", defaultShortcuts: ["Mod+J"], description: 'Open "Jump to note" dialog' }, + + { - actionName: "MarkdownToHTML", - defaultShortcuts: ["Mod+Return"] + separator: "Tabs" }, { actionName: "NewTab", @@ -32,76 +44,13 @@ const DEFAULT_KEYBOARD_ACTIONS = [ }, { actionName: "PreviousTab", - defaultShortcuts: ["Mod+SHIFT+Tab"], + defaultShortcuts: ["Mod+Shift+Tab"], only: ELECTRON }, + + { - actionName: "CreateNoteAfter", - defaultShortcuts: ["Mod+O"] - }, - { - actionName: "CreateNoteInto", - defaultShortcuts: ["Mod+P"] - }, - { - actionName: "ScrollToActiveNote", - defaultShortcuts: ["Mod+."] - }, - { - actionName: "CollapseTree", - defaultShortcuts: ["Alt+C"] - }, - { - actionName: "RunSQL", - defaultShortcuts: ["Mod+return"] - }, - { - actionName: "FocusNote", - defaultShortcuts: ["return"] - }, - { - actionName: "RunCurrentNote", - defaultShortcuts: ["Mod+return"] - }, - { - actionName: "ClipboardCopy", - defaultShortcuts: ["Mod+C"] - }, - { - actionName: "ClipboardPaste", - defaultShortcuts: ["Mod+V"] - }, - { - actionName: "ClipboardCut", - defaultShortcuts: ["Mod+X"] - }, - { - actionName: "SelectAllNotesInParent", - defaultShortcuts: ["Mod+A"] - }, - { - actionName: "Undo", - defaultShortcuts: ["Mod+Z"] - }, - { - actionName: "Redo", - defaultShortcuts: ["Mod+Y"] - }, - { - actionName: "AddLinkToText", - defaultShortcuts: ["Mod+L"] - }, - { - actionName: "CloneNotesTo", - defaultShortcuts: ["Mod+Shift+C"] - }, - { - actionName: "MoveNotesTo", - defaultShortcuts: ["Mod+Shift+C"] - }, - { - actionName: "SearchNotes", - defaultShortcuts: ["Mod+S"] + separator: "Dialogs" }, { actionName: "ShowAttributes", @@ -135,21 +84,87 @@ const DEFAULT_KEYBOARD_ACTIONS = [ actionName: "ShowHelp", defaultShortcuts: ["F1"] }, + { + actionName: "CreateNoteAfter", + defaultShortcuts: ["Mod+O"] + }, + { + actionName: "CreateNoteInto", + defaultShortcuts: ["Mod+P"] + }, + { + actionName: "ScrollToActiveNote", + defaultShortcuts: ["Mod+."] + }, + { + actionName: "CollapseTree", + defaultShortcuts: ["Alt+C"] + }, + { + actionName: "FocusNote", + defaultShortcuts: ["return"] + }, + { + actionName: "RunCurrentNote", + defaultShortcuts: ["Mod+return"] + }, + { + actionName: "ClipboardCopy", + defaultShortcuts: ["Mod+C"], + description: "Copy selected notes to the clipboard" + }, + { + actionName: "ClipboardPaste", + defaultShortcuts: ["Mod+V"], + description: "Paste notes from the clipboard into active note" + }, + { + actionName: "ClipboardCut", + defaultShortcuts: ["Mod+X"], + description: "Copy selected notes to the clipboard" + }, + { + actionName: "SelectAllNotesInParent", + defaultShortcuts: ["Mod+A"], + description: "Select all notes from the current note level" + }, + { + separator: "Text note operations" + }, + { + actionName: "Undo", + defaultShortcuts: ["Mod+Z"], + description: "Undo last text operation (applicable on MacOS only)" + }, + { + actionName: "Redo", + defaultShortcuts: ["Mod+Y"], + description: "Undo last text operation (applicable on MacOS only)" + }, + { + actionName: "AddLinkToText", + defaultShortcuts: ["Mod+L"], + description: "Open dialog to add link to the text" + }, + { + actionName: "CloneNotesTo", + defaultShortcuts: ["Mod+Shift+C"] + }, + { + actionName: "MoveNotesTo", + defaultShortcuts: ["Mod+Shift+C"] + }, + { + actionName: "SearchNotes", + defaultShortcuts: ["Mod+S"] + }, { actionName: "ShowSQLConsole", defaultShortcuts: ["Alt+O"] }, { - actionName: "BackInNoteHistory", - defaultShortcuts: ["Alt+Left"] - }, - { - actionName: "ForwardInNoteHistory", - defaultShortcuts: ["Alt+Right"] - }, - { - actionName: "ToggleZenMode", - defaultShortcuts: ["Alt+M"] + actionName: "RunSQL", + defaultShortcuts: ["Mod+return"] }, { actionName: "InsertDateTime", @@ -161,7 +176,7 @@ const DEFAULT_KEYBOARD_ACTIONS = [ }, { actionName: "OpenDevTools", - defaultShortcuts: ["Mod+SHIFT+I"] + defaultShortcuts: ["Mod+Shift+I"] }, { actionName: "FindInText", @@ -171,6 +186,10 @@ const DEFAULT_KEYBOARD_ACTIONS = [ actionName: "ToggleFullscreen", defaultShortcuts: ["F11"] }, + { + actionName: "ToggleZenMode", + defaultShortcuts: ["Alt+M"] + }, { actionName: "ZoomOut", defaultShortcuts: ["Mod+-"] @@ -178,12 +197,18 @@ const DEFAULT_KEYBOARD_ACTIONS = [ { actionName: "ZoomIn", defaultShortcuts: ["Mod+="] - } + }, + { + actionName: "MarkdownToHTML", + defaultShortcuts: ["Mod+Return"] + }, ]; if (process.platform === "darwin") { for (const action of DEFAULT_KEYBOARD_ACTIONS) { - action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("Mod", "Meta")); + if (action.defaultShortcuts) { + action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("Mod", "Meta")); + } } // Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376 @@ -192,7 +217,9 @@ if (process.platform === "darwin") { } else { for (const action of DEFAULT_KEYBOARD_ACTIONS) { - action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("Mod", "Ctrl")); + if (action.defaultShortcuts) { + action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("Mod", "Ctrl")); + } } } @@ -200,7 +227,9 @@ async function getKeyboardActions() { const actions = JSON.parse(JSON.stringify(DEFAULT_KEYBOARD_ACTIONS)); for (const action of actions) { - action.effectiveShortcuts = action.defaultShortcuts.slice(); + if (action.defaultShortcuts) { + action.effectiveShortcuts = action.defaultShortcuts.slice(); + } } for (const option of await optionService.getOptions()) {