mirror of
https://github.com/zadam/trilium.git
synced 2025-03-03 18:49:27 +08:00
CTRL-X and CTRL-V now cuts and pastes tree nodes
This commit is contained in:
parent
81187ebb0e
commit
a13b4a6f7e
2 changed files with 70 additions and 12 deletions
|
@ -1,3 +1,23 @@
|
|||
function pasteAfter(node) {
|
||||
const subjectNode = getNodeByKey(globalClipboardNoteId);
|
||||
|
||||
moveAfterNode(subjectNode, node);
|
||||
|
||||
globalClipboardNoteId = null;
|
||||
}
|
||||
|
||||
function pasteInto(node) {
|
||||
const subjectNode = getNodeByKey(globalClipboardNoteId);
|
||||
|
||||
moveToNode(subjectNode, node);
|
||||
|
||||
globalClipboardNoteId = null;
|
||||
}
|
||||
|
||||
function cut(node) {
|
||||
globalClipboardNoteId = node.key;
|
||||
}
|
||||
|
||||
const contextMenuSetup = {
|
||||
delegate: "span.fancytree-title",
|
||||
autoFocus: true,
|
||||
|
@ -46,21 +66,13 @@ const contextMenuSetup = {
|
|||
decryptSubTree(node.key);
|
||||
}
|
||||
else if (ui.cmd === "cut") {
|
||||
globalClipboardNoteId = node.key;
|
||||
cut(node);
|
||||
}
|
||||
else if (ui.cmd === "pasteAfter") {
|
||||
const subjectNode = getNodeByKey(globalClipboardNoteId);
|
||||
|
||||
moveAfterNode(subjectNode, node);
|
||||
|
||||
globalClipboardNoteId = null;
|
||||
pasteAfter(node);
|
||||
}
|
||||
else if (ui.cmd === "pasteInto") {
|
||||
const subjectNode = getNodeByKey(globalClipboardNoteId);
|
||||
|
||||
moveToNode(subjectNode, node);
|
||||
|
||||
globalClipboardNoteId = null;
|
||||
pasteInto(node);
|
||||
}
|
||||
else if (ui.cmd === "delete") {
|
||||
deleteNode(node);
|
||||
|
|
|
@ -165,7 +165,53 @@ $(() => {
|
|||
nodata: true, // Display a 'no data' status node if result is empty
|
||||
mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
|
||||
},
|
||||
dnd: dragAndDropSetup
|
||||
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
|
||||
// copyPaste("copy", node);
|
||||
// return false;
|
||||
// }
|
||||
// break;
|
||||
case 86:
|
||||
console.log("CTRL-V");
|
||||
|
||||
if (event.ctrlKey) { // Ctrl-V
|
||||
pasteAfter(node);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 88:
|
||||
console.log("CTRL-X");
|
||||
|
||||
if (event.ctrlKey) { // Ctrl-X
|
||||
cut(node);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
globalTree.contextmenu(contextMenuSetup);
|
||||
|
|
Loading…
Reference in a new issue