mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	CTRL-X and CTRL-V now cuts and pastes tree nodes
This commit is contained in:
		
							parent
							
								
									81187ebb0e
								
							
						
					
					
						commit
						a13b4a6f7e
					
				| @ -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 = { | const contextMenuSetup = { | ||||||
|     delegate: "span.fancytree-title", |     delegate: "span.fancytree-title", | ||||||
|     autoFocus: true, |     autoFocus: true, | ||||||
| @ -46,21 +66,13 @@ const contextMenuSetup = { | |||||||
|             decryptSubTree(node.key); |             decryptSubTree(node.key); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "cut") { |         else if (ui.cmd === "cut") { | ||||||
|             globalClipboardNoteId = node.key; |             cut(node); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "pasteAfter") { |         else if (ui.cmd === "pasteAfter") { | ||||||
|             const subjectNode = getNodeByKey(globalClipboardNoteId); |             pasteAfter(node); | ||||||
| 
 |  | ||||||
|             moveAfterNode(subjectNode, node); |  | ||||||
| 
 |  | ||||||
|             globalClipboardNoteId = null; |  | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "pasteInto") { |         else if (ui.cmd === "pasteInto") { | ||||||
|             const subjectNode = getNodeByKey(globalClipboardNoteId); |             pasteInto(node); | ||||||
| 
 |  | ||||||
|             moveToNode(subjectNode, node); |  | ||||||
| 
 |  | ||||||
|             globalClipboardNoteId = null; |  | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "delete") { |         else if (ui.cmd === "delete") { | ||||||
|             deleteNode(node); |             deleteNode(node); | ||||||
|  | |||||||
| @ -165,7 +165,53 @@ $(() => { | |||||||
|                 nodata: true,      // Display a 'no data' status node if result is empty
 |                 nodata: true,      // Display a 'no data' status node if result is empty
 | ||||||
|                 mode: "hide"       // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
 |                 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); |         globalTree.contextmenu(contextMenuSetup); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner