separators and fixes

This commit is contained in:
zadam 2019-11-20 23:10:41 +01:00
parent 5fac2c7633
commit 587134c2f8
3 changed files with 138 additions and 96 deletions

View File

@ -35,17 +35,27 @@ export default class KeyboardShortcutsOptions {
server.get('keyboard-actions').then(actions => {
for (const action of actions) {
const $tr = $("<tr>")
.append($("<td>").text(action.actionName))
.append($("<td>").append(
$(`<input type="text" class="form-control">`)
.val(action.effectiveShortcuts.join(", "))
.attr('data-keyboard-action-name', action.actionName)
.attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", "))
)
const $tr = $("<tr>");
if (action.separator) {
$tr.append(
$('<td colspan="4">')
.attr("style","background-color: var(--accented-background-color); font-weight: bold;")
.text(action.separator)
)
.append($("<td>").text(action.defaultShortcuts.join(", ")))
.append($("<td>").text(action.description));
}
else {
$tr.append($("<td>").text(action.actionName))
.append($("<td>").append(
$(`<input type="text" class="form-control">`)
.val(action.effectiveShortcuts.join(", "))
.attr('data-keyboard-action-name', action.actionName)
.attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", "))
)
)
.append($("<td>").text(action.defaultShortcuts.join(", ")))
.append($("<td>").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);

View File

@ -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);
}
}
});
}

View File

@ -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()) {