From 893b6053d22c159d6197900c988f0007eca4840d Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 13 Oct 2020 23:41:55 +0200 Subject: [PATCH] provide also explicit unhoist keyboard shortcut, #1305 --- src/public/app/services/entrypoints.js | 4 ++++ src/public/app/services/hoisted_note.js | 4 ++++ src/public/app/services/keyboard_actions.js | 3 ++- src/public/app/services/tree_context_menu.js | 2 +- src/public/app/widgets/note_tree.js | 6 +++++- src/services/keyboard_actions.js | 6 ++++++ 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.js index 5d09d5dbc..e62559f3f 100644 --- a/src/public/app/services/entrypoints.js +++ b/src/public/app/services/entrypoints.js @@ -91,6 +91,10 @@ export default class Entrypoints extends Component { } } + async unhoistCommand() { + hoistedNoteService.unhoist(); + } + copyWithoutFormattingCommand() { utils.copySelectionToClipboard(); } diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.js index 334df930d..c6ad0d626 100644 --- a/src/public/app/services/hoisted_note.js +++ b/src/public/app/services/hoisted_note.js @@ -8,6 +8,10 @@ function getHoistedNoteId() { } async function setHoistedNoteId(noteId) { + if (getHoistedNoteId() === noteId) { + return; + } + await options.save('hoistedNoteId', noteId); await treeCache.loadInitialTree(); diff --git a/src/public/app/services/keyboard_actions.js b/src/public/app/services/keyboard_actions.js index ab7fffbfc..53ea4dcaf 100644 --- a/src/public/app/services/keyboard_actions.js +++ b/src/public/app/services/keyboard_actions.js @@ -111,5 +111,6 @@ export default { setElementActionHandler, updateDisplayedShortcuts, setupActionsForElement, - getActionsForScope + getActionsForScope, + getAction }; diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index b37ef28ba..0cc68e0ff 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -69,7 +69,7 @@ class TreeContextMenu { { title: 'Search in subtree ', command: "searchInSubtree", uiIcon: "search", enabled: notSearch && noSelectedNotes }, isHoisted ? null : { title: 'Hoist note ', command: "toggleNoteHoisting", uiIcon: "empty", enabled: noSelectedNotes && notSearch }, - !isHoisted || !isNotRoot ? null : { title: 'Unhoist note ', command: "toggleNoteHoisting", uiIcon: "arrow-up" }, + !isHoisted || !isNotRoot ? null : { title: 'Unhoist note ', command: "toggleNoteHoisting", uiIcon: "arrow-from-bottom" }, { title: 'Edit branch prefix ', command: "editBranchPrefix", uiIcon: "empty", enabled: isNotRoot && parentNotSearch && noSelectedNotes}, { title: "Advanced", uiIcon: "empty", enabled: true, items: [ diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 39e4b52be..666e74bb1 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -460,7 +460,11 @@ export default class NoteTreeWidget extends TabAwareWidget { && node.data.noteId === hoistedNoteService.getHoistedNoteId() && $span.find('.unhoist-button').length === 0) { - const unhoistButton = $('[unhoist]'); + const action = await keyboardActionsService.getAction('unhoist'); + let shortcuts = action.effectiveShortcuts.join(','); + shortcuts = shortcuts ? `(${shortcuts})` : ''; + + const unhoistButton = $(`[unhoist]`); // prepending since appending could push out (when note title is too long) // the button too much to the right so that it's not visible diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index 8285ce255..1db1ce37d 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -352,6 +352,12 @@ const DEFAULT_KEYBOARD_ACTIONS = [ description: "Toggles note hoisting of active note", scope: "window" }, + { + actionName: "unhoist", + defaultShortcuts: ["Alt+U"], + description: "Unhoist from anywhere", + scope: "window" + }, { actionName: "reloadFrontendApp", defaultShortcuts: ["F5", "CommandOrControl+R"],