From de9bab11818473b7c832f2b3cc413a49d33a6484 Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 27 Dec 2017 21:12:54 -0500 Subject: [PATCH] fixed keyboard controlled clipboard --- public/javascripts/note_tree.js | 72 ++++++++++----------------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js index 90a0842d3..9890a9ff4 100644 --- a/public/javascripts/note_tree.js +++ b/public/javascripts/note_tree.js @@ -432,6 +432,27 @@ const noteTree = (function() { "alt+-": node => { collapseTree(node); }, + "ctrl+c": node => { + contextMenu.copy(node); + + showMessage("Note copied into clipboard."); + + return false; + }, + "ctrl+x": node => { + contextMenu.cut(node); + + showMessage("Note cut into clipboard."); + + return false; + }, + "ctrl+v": node => { + contextMenu.pasteInto(node); + + showMessage("Note pasted from clipboard into current note."); + + return false; + }, // code below shouldn't be necessary normally, however there's some problem with interaction with context menu plugin // after opening context menu, standard shortcuts don't work, but they are detected here // so we essentially takeover the standard handling with our implementation. @@ -513,57 +534,6 @@ const noteTree = (function() { mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead) }, dnd: dragAndDropSetup, - keydown: (event, data) => { - const node = data.node; - // Eat keyboard events, when a menu is open - if ($(".contextMenu:visible").length > 0) - return false; - - switch (event.which) { - // Open context menu on [Space] key (simulate right click) - case 32: // [Space] - $(node.span).trigger("mousedown", { - preventDefault: true, - button: 2 - }) - .trigger("mouseup", { - preventDefault: true, - pageX: node.span.offsetLeft, - pageY: node.span.offsetTop, - button: 2 - }); - return false; - - // Handle Ctrl+C, +X and +V - case 67: - if (event.ctrlKey) { // Ctrl+C - contextMenu.copy(node); - - showMessage("Note copied into clipboard."); - - return false; - } - break; - case 88: - if (event.ctrlKey) { // Ctrl+X - contextMenu.cut(node); - - showMessage("Note cut into clipboard."); - - return false; - } - break; - case 86: - if (event.ctrlKey) { // Ctrl+V - contextMenu.pasteInto(node); - - showMessage("Note pasted from clipboard into current note."); - - return false; - } - break; - } - }, lazyLoad: function(event, data){ const node = data.node.data;