reorganization of shortcuts in the options

This commit is contained in:
zadam 2019-11-24 10:40:18 +01:00
parent 1f37d00e42
commit c400a7143c
8 changed files with 223 additions and 181 deletions

View File

@ -4,6 +4,8 @@ import utils from "../../services/utils.js";
const TPL = `
<h4>Keyboard shortcuts</h4>
<p>Multiple shortcuts for the same action can be separated by comma.</p>
<div style="overflow: auto; height: 500px;">
<table id="keyboard-shortcut-table" cellpadding="10">
<thead>

View File

@ -31,31 +31,31 @@ function registerEntrypoints() {
jQuery.hotkeys.options.filterContentEditable = false;
jQuery.hotkeys.options.filterTextInputs = false;
keyboardActionService.setActionHandler("AddLinkToText", () => import(ADD_LINK).then(d => d.showDialog()));
keyboardActionService.setGlobalActionHandler("AddLinkToText", () => import(ADD_LINK).then(d => d.showDialog()));
const showJumpToNoteDialog = () => import(JUMP_TO_NOTE).then(d => d.showDialog());
$("#jump-to-note-dialog-button").on('click', showJumpToNoteDialog);
keyboardActionService.setActionHandler("JumpToNote", showJumpToNoteDialog);
keyboardActionService.setGlobalActionHandler("JumpToNote", showJumpToNoteDialog);
const showRecentChanges = () => import(RECENT_CHANGES).then(d => d.showDialog());
$("#recent-changes-button").on('click', showRecentChanges);
keyboardActionService.setActionHandler("ShowRecentChanges", showRecentChanges);
keyboardActionService.setGlobalActionHandler("ShowRecentChanges", showRecentChanges);
$("#enter-protected-session-button").on('click', protectedSessionService.enterProtectedSession);
$("#leave-protected-session-button").on('click', protectedSessionService.leaveProtectedSession);
$("#toggle-search-button").on('click', searchNotesService.toggleSearch);
keyboardActionService.setActionHandler('SearchNotes', searchNotesService.toggleSearch);
keyboardActionService.setGlobalActionHandler('SearchNotes', searchNotesService.toggleSearch);
const $noteTabContainer = $("#note-tab-container");
const showAttributesDialog = () => import(ATTRIBUTES).then(d => d.showDialog());
$noteTabContainer.on("click", ".show-attributes-button", showAttributesDialog);
keyboardActionService.setActionHandler("ShowAttributes", showAttributesDialog);
keyboardActionService.setGlobalActionHandler("ShowAttributes", showAttributesDialog);
const showNoteInfoDialog = () => import(NOTE_INFO).then(d => d.showDialog());
$noteTabContainer.on("click", ".show-note-info-button", showNoteInfoDialog);
keyboardActionService.setActionHandler("ShowNoteInfo", showNoteInfoDialog);
keyboardActionService.setGlobalActionHandler("ShowNoteInfo", showNoteInfoDialog);
const showNoteRevisionsDialog = function() {
if ($(this).hasClass("disabled")) {
@ -66,7 +66,7 @@ function registerEntrypoints() {
};
$noteTabContainer.on("click", ".show-note-revisions-button", showNoteRevisionsDialog);
keyboardActionService.setActionHandler("ShowNoteRevisions", showNoteRevisionsDialog);
keyboardActionService.setGlobalActionHandler("ShowNoteRevisions", showNoteRevisionsDialog);
const showNoteSourceDialog = function() {
if ($(this).hasClass("disabled")) {
@ -77,33 +77,33 @@ function registerEntrypoints() {
};
$noteTabContainer.on("click", ".show-source-button", showNoteSourceDialog);
keyboardActionService.setActionHandler("ShowNoteSource", showNoteSourceDialog);
keyboardActionService.setGlobalActionHandler("ShowNoteSource", showNoteSourceDialog);
const showLinkMapDialog = () => import(LINK_MAP).then(d => d.showDialog());
$noteTabContainer.on("click", ".show-link-map-button", showLinkMapDialog);
keyboardActionService.setActionHandler("ShowLinkMap", showLinkMapDialog);
keyboardActionService.setGlobalActionHandler("ShowLinkMap", showLinkMapDialog);
const showOptionsDialog = () => import(OPTIONS).then(d => d.showDialog());
$("#options-button").on('click', showOptionsDialog);
keyboardActionService.setActionHandler("ShowOptions", showOptionsDialog);
keyboardActionService.setGlobalActionHandler("ShowOptions", showOptionsDialog);
const showHelpDialog = () => import(HELP).then(d => d.showDialog());
$("#show-help-button").on('click', showHelpDialog);
keyboardActionService.setActionHandler("ShowHelp", showHelpDialog);
keyboardActionService.setGlobalActionHandler("ShowHelp", showHelpDialog);
const showSqlConsoleDialog = () => import(SQL_CONSOLE).then(d => d.showDialog());
$("#open-sql-console-button").on('click', showSqlConsoleDialog);
keyboardActionService.setActionHandler("ShowSQLConsole", showSqlConsoleDialog);
keyboardActionService.setGlobalActionHandler("ShowSQLConsole", showSqlConsoleDialog);
$("#show-about-dialog-button").on('click', () => import(ABOUT).then(d => d.showDialog()));
if (utils.isElectron()) {
$("#history-navigation").show();
$("#history-back-button").on('click', window.history.back);
keyboardActionService.setActionHandler("BackInNoteHistory", window.history.back);
keyboardActionService.setGlobalActionHandler("BackInNoteHistory", window.history.back);
$("#history-forward-button").on('click', window.history.forward);
keyboardActionService.setActionHandler("ForwardInNoteHistory", window.history.forward);
keyboardActionService.setGlobalActionHandler("ForwardInNoteHistory", window.history.forward);
}
// hide (toggle) everything except for the note content for zen mode
@ -113,9 +113,9 @@ function registerEntrypoints() {
};
$("#toggle-zen-mode-button").on('click', toggleZenMode);
keyboardActionService.setActionHandler("ToggleZenMode", toggleZenMode);
keyboardActionService.setGlobalActionHandler("ToggleZenMode", toggleZenMode);
keyboardActionService.setActionHandler("InsertDateTimeToText", () => {
keyboardActionService.setGlobalActionHandler("InsertDateTimeToText", () => {
const date = new Date();
const dateString = utils.formatDateTime(date);
@ -123,7 +123,7 @@ function registerEntrypoints() {
});
$("#reload-frontend-button").on('click', utils.reloadApp);
keyboardActionService.setActionHandler("ReloadFrontendApp", utils.reloadApp);
keyboardActionService.setGlobalActionHandler("ReloadFrontendApp", utils.reloadApp);
$("#open-dev-tools-button").toggle(utils.isElectron());
@ -135,7 +135,7 @@ function registerEntrypoints() {
};
$("#open-dev-tools-button").on('click', openDevTools);
keyboardActionService.setActionHandler("OpenDevTools", openDevTools);
keyboardActionService.setGlobalActionHandler("OpenDevTools", openDevTools);
}
let findInPage;
@ -157,7 +157,7 @@ function registerEntrypoints() {
caseSelectedColor: 'var(--main-border-color)'
});
keyboardActionService.setActionHandler("FindInText", () => {
keyboardActionService.setGlobalActionHandler("FindInText", () => {
if (!glob.activeDialog || !glob.activeDialog.is(":visible")) {
findInPage.openFindWindow();
}
@ -177,7 +177,7 @@ function registerEntrypoints() {
$("#toggle-fullscreen-button").on('click', toggleFullscreen);
keyboardActionService.setActionHandler("ToggleFullscreen", toggleFullscreen);
keyboardActionService.setGlobalActionHandler("ToggleFullscreen", toggleFullscreen);
}
else {
// outside of electron this is handled by the browser
@ -185,8 +185,8 @@ function registerEntrypoints() {
}
if (utils.isElectron()) {
keyboardActionService.setActionHandler("ZoomOut", zoomService.decreaseZoomFactor);
keyboardActionService.setActionHandler("ZoomIn", zoomService.increaseZoomFactor);
keyboardActionService.setGlobalActionHandler("ZoomOut", zoomService.decreaseZoomFactor);
keyboardActionService.setGlobalActionHandler("ZoomIn", zoomService.increaseZoomFactor);
}
$(document).on('click', "a[data-action='note-revision']", async event => {
@ -201,7 +201,7 @@ function registerEntrypoints() {
return false;
});
keyboardActionService.setActionHandler("CloneNotesTo", () => import(CLONE_TO).then(d => {
keyboardActionService.setGlobalActionHandler("CloneNotesTo", () => import(CLONE_TO).then(d => {
const activeNode = treeService.getActiveNode();
const selectedOrActiveNodes = treeService.getSelectedOrActiveNodes(activeNode);
@ -211,7 +211,7 @@ function registerEntrypoints() {
d.showDialog(noteIds);
}));
keyboardActionService.setActionHandler("MoveNotesTo", () => import(MOVE_TO).then(d => {
keyboardActionService.setGlobalActionHandler("MoveNotesTo", () => import(MOVE_TO).then(d => {
const activeNode = treeService.getActiveNode();
const selectedOrActiveNodes = treeService.getSelectedOrActiveNodes(activeNode);
@ -219,7 +219,7 @@ function registerEntrypoints() {
d.showDialog(selectedOrActiveNodes);
}));
keyboardActionService.setActionHandler("CreateNoteIntoDayNote", async () => {
keyboardActionService.setGlobalActionHandler("CreateNoteIntoDayNote", async () => {
const todayNote = await dateNoteService.getTodayNote();console.log(todayNote);
const notePath = await treeService.getSomeNotePath(todayNote);
@ -233,14 +233,14 @@ function registerEntrypoints() {
});
});
keyboardActionService.setActionHandler("EditBranchPrefix", async () => {
keyboardActionService.setGlobalActionHandler("EditBranchPrefix", async () => {
const node = treeService.getActiveNode();
const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js");
editBranchPrefixDialog.showDialog(node);
});
keyboardActionService.setActionHandler("ToggleNoteHoisting", async () => {
keyboardActionService.setGlobalActionHandler("ToggleNoteHoisting", async () => {
const node = treeService.getActiveNode();
hoistedNoteService.getHoistedNoteId().then(async hoistedNoteId => {
@ -257,7 +257,7 @@ function registerEntrypoints() {
});
});
keyboardActionService.setActionHandler("SearchInSubtree", () => {
keyboardActionService.setGlobalActionHandler("SearchInSubtree", () => {
const node = treeService.getActiveNode();
searchNotesService.searchInSubtree(node.data.noteId);

View File

@ -33,7 +33,7 @@ const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => {
}
});
function setActionHandler(actionName, handler) {
function setGlobalActionHandler(actionName, handler) {
keyboardActionsLoaded.then(() => {
const action = keyboardActionRepo[actionName];
@ -51,6 +51,24 @@ function setActionHandler(actionName, handler) {
});
}
function setElementActionHandler($el, actionName, handler) {
keyboardActionsLoaded.then(() => {
const action = keyboardActionRepo[actionName];
if (!action) {
throw new Error(`Cannot find keyboard action '${actionName}'`);
}
// not setting action.handler since this is not global
for (const shortcut of action.effectiveShortcuts) {
if (shortcut) {
utils.bindElShortcut($el, shortcut, handler);
}
}
});
}
async function triggerAction(actionName) {
const action = getAction(actionName);
@ -105,7 +123,8 @@ function updateDisplayedShortcuts($container) {
$(() => updateDisplayedShortcuts($(document)));
export default {
setActionHandler,
setGlobalActionHandler,
setElementActionHandler,
triggerAction,
getAction,
updateDisplayedShortcuts

View File

@ -420,17 +420,17 @@ $(tabRow.el).on('contextmenu', '.note-tab', e => {
});
});
keyboardActionService.setActionHandler('OpenNewTab', () => {
keyboardActionService.setGlobalActionHandler('OpenNewTab', () => {
openEmptyTab();
});
keyboardActionService.setActionHandler('CloseActiveTab', () => {
keyboardActionService.setGlobalActionHandler('CloseActiveTab', () => {
if (tabRow.activeTabEl) {
tabRow.removeTab(tabRow.activeTabEl);
}
});
keyboardActionService.setActionHandler('ActivateNextTab', () => {
keyboardActionService.setGlobalActionHandler('ActivateNextTab', () => {
const nextTab = tabRow.nextTabEl;
if (nextTab) {
@ -438,7 +438,7 @@ keyboardActionService.setActionHandler('ActivateNextTab', () => {
}
});
keyboardActionService.setActionHandler('ActivatePreviousTab', () => {
keyboardActionService.setGlobalActionHandler('ActivatePreviousTab', () => {
const prevTab = tabRow.previousTabEl;
if (prevTab) {

View File

@ -3,7 +3,7 @@ import bundleService from "./bundle.js";
import toastService from "./toast.js";
import server from "./server.js";
import noteDetailService from "./note_detail.js";
import utils from "./utils.js";
import keyboardActionService from "./keyboard_actions.js";
class NoteDetailCode {
@ -17,7 +17,7 @@ class NoteDetailCode {
this.$editorEl = this.$component.find('.note-detail-code-editor');
this.$executeScriptButton = ctx.$tabContent.find(".execute-script-button");
utils.bindElShortcut(ctx.$tabContent, "ctrl+return", () => this.executeCurrentNote());
keyboardActionService.setElementActionHandler(ctx.$tabContent, 'RunActiveNote', () => this.executeCurrentNote());
this.$executeScriptButton.on('click', () => this.executeCurrentNote());
}

View File

@ -796,7 +796,7 @@ ws.subscribeToOutsideSyncMessages(async syncData => {
}
});
keyboardActionService.setActionHandler('CreateNoteAfter', async () => {
keyboardActionService.setGlobalActionHandler('CreateNoteAfter', async () => {
const node = getActiveNode();
const parentNoteId = node.data.parentNoteId;
const isProtected = await treeUtils.getParentProtectedStatus(node);
@ -868,9 +868,9 @@ async function reloadNotes(noteIds, activateNotePath = null) {
window.glob.createNoteInto = createNoteInto;
keyboardActionService.setActionHandler('CreateNoteInto', createNoteInto);
keyboardActionService.setGlobalActionHandler('CreateNoteInto', createNoteInto);
keyboardActionService.setActionHandler('ScrollToActiveNote', scrollToActiveNote);
keyboardActionService.setGlobalActionHandler('ScrollToActiveNote', scrollToActiveNote);
$(window).bind('hashchange', async function() {
if (isNotePathInAddress()) {
@ -908,7 +908,7 @@ async function duplicateNote(noteId, parentNoteId) {
}
keyboardActionService.setActionHandler('CollapseTree', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument
keyboardActionService.setGlobalActionHandler('CollapseTree', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument
$collapseTreeButton.on('click', () => collapseTree());
$createTopLevelNoteButton.on('click', createNewTopLevelNote);

View File

@ -139,6 +139,7 @@ function bindElShortcut($el, keyboardShortcut, handler) {
if (isDesktop()) {
keyboardShortcut = keyboardShortcut
.toLowerCase()
.replace("enter", "return")
.replace("ctrl+alt", "alt+ctrl")
.replace("meta+alt", "alt+meta"); // alt needs to be first

View File

@ -26,6 +26,139 @@ const DEFAULT_KEYBOARD_ACTIONS = [
defaultShortcuts: ["CommandOrControl+J"],
description: 'Open "Jump to note" dialog'
},
{
actionName: "ScrollToActiveNote",
defaultShortcuts: ["CommandOrControl+."]
},
{
actionName: "SearchNotes",
defaultShortcuts: ["CommandOrControl+S"]
},
{
actionName: "SearchInSubtree",
defaultShortcuts: ["CommandOrControl+Shift+S"],
description: "Search for notes in the active note's subtree"
},
{
actionName: "CollapseTree",
defaultShortcuts: ["Alt+C"]
},
{
actionName: "CollapseSubtree",
defaultShortcuts: ["Alt+-"],
description: "Collapses subtree of current note"
},
{
actionName: "FocusNote",
defaultShortcuts: ["Enter"]
},
{
actionName: "ActivateParentNote",
defaultShortcuts: ["Backspace"],
description: "Activates parent note of currently active note"
},
{
actionName: "SortChildNotes",
defaultShortcuts: ["Alt+S"],
description: "Sort child notes"
},
{
separator: "Creating and moving notes"
},
{
actionName: "CreateNoteAfter",
defaultShortcuts: ["CommandOrControl+O"]
},
{
actionName: "CreateNoteInto",
defaultShortcuts: ["CommandOrControl+P"]
},
{
actionName: "CreateNoteIntoDayNote",
defaultShortcuts: ["global:CommandOrControl+Alt+P"],
description: "Create and open subnote of a current day note"
},
{
actionName: "DeleteNotes",
defaultShortcuts: ["Delete"],
description: "Delete note"
},
{
actionName: "MoveNoteUp",
defaultShortcuts: ["CommandOrControl+Up"],
description: "Move note up"
},
{
actionName: "MoveNoteDown",
defaultShortcuts: ["CommandOrControl+Down"],
description: "Move note down"
},
{
actionName: "MoveNoteUpInHierarchy",
defaultShortcuts: ["CommandOrControl+Left"],
description: "Move note up in hierarchy"
},
{
actionName: "MoveNoteDownInHierarchy",
defaultShortcuts: ["CommandOrControl+Right"],
description: "Move note down in hierarchy"
},
{
actionName: "EditNoteTitle",
defaultShortcuts: ["Enter"],
description: "Edit active note title"
},
{
actionName: "EditBranchPrefix",
defaultShortcuts: ["F2"],
description: "Show Edit branch prefix dialog"
},
{
actionName: "CloneNotesTo",
defaultShortcuts: ["CommandOrControl+Shift+C"]
},
{
actionName: "MoveNotesTo",
defaultShortcuts: ["CommandOrControl+Shift+C"]
},
{
separator: "Note clipboard"
},
{
actionName: "CopyNotesToClipboard",
defaultShortcuts: ["CommandOrControl+C"],
description: "Copy selected notes to the clipboard"
},
{
actionName: "PasteNotesFromClipboard",
defaultShortcuts: ["CommandOrControl+V"],
description: "Paste notes from the clipboard into active note"
},
{
actionName: "CutNotesToClipboard",
defaultShortcuts: ["CommandOrControl+X"],
description: "Cut selected notes to the clipboard"
},
{
actionName: "SelectAllNotesInParent",
defaultShortcuts: ["CommandOrControl+A"],
description: "Select all notes from the current note level"
},
{
actionName: "AddNoteAboveToSelection",
defaultShortcuts: ["Shift+Up"],
description: "Add note above to the selection"
},
{
actionName: "AddNoteBelowToSelection",
defaultShortcuts: ["Shift+Down"],
description: "Add note above to the selection"
},
{
@ -80,164 +213,51 @@ const DEFAULT_KEYBOARD_ACTIONS = [
actionName: "ShowRecentChanges",
defaultShortcuts: []
},
{
actionName: "ShowSQLConsole",
defaultShortcuts: ["Alt+O"]
},
{
actionName: "ShowHelp",
defaultShortcuts: ["F1"]
},
{
separator: "Text note operations"
},
{
actionName: "AddLinkToText",
defaultShortcuts: ["CommandOrControl+L"],
description: "Open dialog to add link to the text"
},
{
actionName: "InsertDateTimeToText",
defaultShortcuts: ["Alt+T"]
},
{
separator: "Other"
},
{
actionName: "PrintActiveNote",
defaultShortcuts: []
},
{
actionName: "CreateNoteAfter",
defaultShortcuts: ["CommandOrControl+O"]
},
{
actionName: "CreateNoteInto",
defaultShortcuts: ["CommandOrControl+P"]
},
{
actionName: "CreateNoteIntoDayNote",
defaultShortcuts: ["global:CommandOrControl+Alt+P"],
description: "Create and open subnote of a current day note"
},
{
actionName: "ScrollToActiveNote",
defaultShortcuts: ["CommandOrControl+."]
},
{
actionName: "CollapseTree",
defaultShortcuts: ["Alt+C"]
},
{
actionName: "FocusNote",
defaultShortcuts: ["return"]
},
{
actionName: "RunCurrentNote",
defaultShortcuts: ["CommandOrControl+return"]
},
{
actionName: "DeleteNotes",
defaultShortcuts: ["Delete"],
description: "Delete note"
},
{
actionName: "MoveNoteUp",
defaultShortcuts: ["CommandOrControl+Up"],
description: "Move note up"
},
{
actionName: "MoveNoteDown",
defaultShortcuts: ["CommandOrControl+Down"],
description: "Move note down"
},
{
actionName: "MoveNoteUpInHierarchy",
defaultShortcuts: ["CommandOrControl+Left"],
description: "Move note up in hierarchy"
},
{
actionName: "MoveNoteDownInHierarchy",
defaultShortcuts: ["CommandOrControl+Right"],
description: "Move note down in hierarchy"
},
{
actionName: "AddNoteAboveToSelection",
defaultShortcuts: ["Shift+Up"],
description: "Add note above to the selection"
},
{
actionName: "AddNoteBelowToSelection",
defaultShortcuts: ["Shift+Down"],
description: "Add note above to the selection"
},
{
actionName: "CopyNotesToClipboard",
defaultShortcuts: ["CommandOrControl+C"],
description: "Copy selected notes to the clipboard"
},
{
actionName: "PasteNotesFromClipboard",
defaultShortcuts: ["CommandOrControl+V"],
description: "Paste notes from the clipboard into active note"
},
{
actionName: "CutNotesToClipboard",
defaultShortcuts: ["CommandOrControl+X"],
description: "Cut selected notes to the clipboard"
},
{
actionName: "EditBranchPrefix",
defaultShortcuts: ["F2"],
description: "Show Edit branch prefix dialog"
},
{
actionName: "CollapseSubtree",
defaultShortcuts: ["Alt+-"],
description: "Collapses subtree of current note"
},
{
actionName: "SortChildNotes",
defaultShortcuts: ["Alt+S"],
description: "Sort child notes"
},
{
actionName: "ActivateParentNote",
defaultShortcuts: ["Backspace"],
description: "Activates parent note of currently active note"
actionName: "RunActiveNote",
defaultShortcuts: ["CommandOrControl+Enter"],
description: "Run active JavaScript (frontend/backend) code note"
},
{
actionName: "ToggleNoteHoisting",
defaultShortcuts: ["Alt+H"],
description: "Toggles note hoisting of active note"
},
{
actionName: "SearchInSubtree",
defaultShortcuts: ["CommandOrControl+Shift+S"],
description: "Search for notes in the active note's subtree"
},
{
actionName: "EditNoteTitle",
defaultShortcuts: ["Return"],
description: "Edit active note title"
},
{
actionName: "SelectAllNotesInParent",
defaultShortcuts: ["CommandOrControl+A"],
description: "Select all notes from the current note level"
},
{
separator: "Text note operations"
},
{
actionName: "AddLinkToText",
defaultShortcuts: ["CommandOrControl+L"],
description: "Open dialog to add link to the text"
},
{
actionName: "CloneNotesTo",
defaultShortcuts: ["CommandOrControl+Shift+C"]
},
{
actionName: "MoveNotesTo",
defaultShortcuts: ["CommandOrControl+Shift+C"]
},
{
actionName: "SearchNotes",
defaultShortcuts: ["CommandOrControl+S"]
},
{
actionName: "ShowSQLConsole",
defaultShortcuts: ["Alt+O"]
},
{
actionName: "RunSQL",
defaultShortcuts: ["CommandOrControl+return"]
},
{
actionName: "InsertDateTimeToText",
defaultShortcuts: ["Alt+T"]
defaultShortcuts: ["CommandOrControl+Enter"]
},
{
actionName: "ReloadFrontendApp",