From 1f7f7d105ce227b241cadc0eb0e74fb65fc8b0e8 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 4 Sep 2017 13:27:54 -0400 Subject: [PATCH] implemented insert after and insert into in context menu --- static/js/tree.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/static/js/tree.js b/static/js/tree.js index 5708fb7f7..91483942f 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -66,9 +66,13 @@ function deleteNode(node) { } } +function getParentKey(node) { + return (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key; +} + const keybindings = { "insert": function(node) { - let parentKey = (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key; + const parentKey = getParentKey(node); createNote(node, parentKey, 'after'); }, @@ -313,22 +317,19 @@ $(function(){ ui.menu.prevKeyboard = node.tree.options.keyboard; node.tree.options.keyboard = false; }, - close: function (event, ui) { - // Restore tree keyboard handling - // console.log("close", event, ui, this) - // Note: ui is passed since v1.15.0 - const node = $.ui.fancytree.getNode(ui.target); - - // in case of move operations this can be null - if (node) { - node.tree.options.keyboard = ui.menu.prevKeyboard; - node.setFocus(); - } - }, + close: function (event, ui) {}, select: function (event, ui) { const node = $.ui.fancytree.getNode(ui.target); - if (ui.cmd === "cut") { + if (ui.cmd === "insertNoteHere") { + const parentKey = getParentKey(node); + + createNote(node, parentKey, 'after'); + } + else if (ui.cmd === "insertChildNote") { + createNote(node, node.key, 'into'); + } + else if (ui.cmd === "cut") { globalClipboardNoteId = node.key; } else if (ui.cmd === "pasteAfter") {