fixed keyboard controlled clipboard

This commit is contained in:
azivner 2017-12-27 21:12:54 -05:00
parent 136375cf11
commit de9bab1181

View file

@ -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;