From 943b35fb7db88ab9dceba51010c8e39eaa072554 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 13 Jun 2019 22:55:06 +0200 Subject: [PATCH] fix delete with keyboard and context menu regarding the selection --- src/public/javascripts/services/tree.js | 6 ------ src/public/javascripts/services/tree_context_menu.js | 8 +++++++- src/public/javascripts/services/tree_keybindings.js | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index b9d26b87f..ee6ab8b93 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -453,12 +453,6 @@ function initFancyTree(tree) { $tree.on('contextmenu', '.fancytree-node', function(e) { const node = $.ui.fancytree.getNode(e); - // right click resets selection to just this node - // this is important when e.g. you right click on a note while having different note active - // and then click on delete - obviously you want to delete only that one right-clicked - node.setSelected(true); - clearSelectedNodes(); - contextMenuWidget.initContextMenu(e, new TreeContextMenu(node)); return false; // blocks default browser right click menu diff --git a/src/public/javascripts/services/tree_context_menu.js b/src/public/javascripts/services/tree_context_menu.js index a12893511..cda8f958e 100644 --- a/src/public/javascripts/services/tree_context_menu.js +++ b/src/public/javascripts/services/tree_context_menu.js @@ -122,7 +122,13 @@ class TreeContextMenu { clipboard.pasteInto(this.node); } else if (cmd === "delete") { - treeChangesService.deleteNodes(treeService.getSelectedNodes(true)); + let notesToDelete = treeService.getSelectedNodes(true); + + if (notesToDelete.length === 0) { + notesToDelete.push(this.node); + } + + treeChangesService.deleteNodes(notesToDelete); } else if (cmd === "export") { exportDialog.showDialog("subtree"); diff --git a/src/public/javascripts/services/tree_keybindings.js b/src/public/javascripts/services/tree_keybindings.js index 8236051dc..755d9153d 100644 --- a/src/public/javascripts/services/tree_keybindings.js +++ b/src/public/javascripts/services/tree_keybindings.js @@ -7,7 +7,13 @@ import clipboard from "./clipboard.js"; const keyBindings = { "del": node => { - treeChangesService.deleteNodes(treeService.getSelectedNodes(true)); + let notesToDelete = treeService.getSelectedNodes(true); + + if (notesToDelete.length === 0) { + notesToDelete.push(node); + } + + treeChangesService.deleteNodes(notesToDelete); }, "ctrl+up": node => { const beforeNode = node.getPrevSibling();