mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	reduce flicker of "create new day note"
This commit is contained in:
		| @@ -220,17 +220,17 @@ function registerEntrypoints() { | |||||||
|     })); |     })); | ||||||
|      |      | ||||||
|     keyboardActionService.setGlobalActionHandler("CreateNoteIntoDayNote", async () => { |     keyboardActionService.setGlobalActionHandler("CreateNoteIntoDayNote", async () => { | ||||||
|         const todayNote = await dateNoteService.getTodayNote();console.log(todayNote); |         const todayNote = await dateNoteService.getTodayNote(); | ||||||
|         const notePath = await treeService.getSomeNotePath(todayNote); |         const notePath = await treeService.getSomeNotePath(todayNote); | ||||||
|  |  | ||||||
|         const node = await treeService.expandToNote(notePath); |         const node = await treeService.expandToNote(notePath); | ||||||
|  |  | ||||||
|         await noteDetailService.openEmptyTab(false); |         const {note} = await treeService.createNote(node, todayNote.noteId, 'into', { | ||||||
|  |  | ||||||
|         await treeService.createNote(node, todayNote.noteId, 'into', { |  | ||||||
|             type: "text", |             type: "text", | ||||||
|             isProtected: node.data.isProtected |             isProtected: node.data.isProtected | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|  |         await noteDetailService.openInTab(note.noteId, true); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     keyboardActionService.setGlobalActionHandler("EditBranchPrefix", async () => { |     keyboardActionService.setGlobalActionHandler("EditBranchPrefix", async () => { | ||||||
|   | |||||||
| @@ -1,35 +1,11 @@ | |||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
|  |  | ||||||
| class KeyboardAction { |  | ||||||
| 	constructor(params) { |  | ||||||
| 		/** @property {string} */ |  | ||||||
| 		this.actionName = params.actionName; |  | ||||||
| 		/** @property {string[]} */ |  | ||||||
| 		this.defaultShortcuts = params.defaultShortcuts; |  | ||||||
| 		/** @property {string[]} */ |  | ||||||
| 		this.effectiveShortcuts = params.effectiveShortcuts; |  | ||||||
| 		/** @property {string} */ |  | ||||||
| 		this.description = params.description; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	addShortcut(shortcut) { |  | ||||||
| 		this.effectiveShortcuts.push(shortcut); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** |  | ||||||
| 	 * @param {string|string[]} shortcuts |  | ||||||
| 	 */ |  | ||||||
| 	replaceShortcuts(shortcuts) { |  | ||||||
| 		this.effectiveShortcuts = Array.isArray(shortcuts) ? shortcuts : [shortcuts]; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| const keyboardActionRepo = {}; | const keyboardActionRepo = {}; | ||||||
|  |  | ||||||
| const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => { | const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => { | ||||||
| 	for (const action of actions) { | 	for (const action of actions) { | ||||||
| 		keyboardActionRepo[action.actionName] = new KeyboardAction(action); | 		keyboardActionRepo[action.actionName] = action; | ||||||
| 	} | 	} | ||||||
| }); | }); | ||||||
|  |  | ||||||
| @@ -54,7 +30,7 @@ function setGlobalActionHandler(actionName, handler) { | |||||||
| 		action.handler = handler; | 		action.handler = handler; | ||||||
|  |  | ||||||
| 		for (const shortcut of action.effectiveShortcuts) { | 		for (const shortcut of action.effectiveShortcuts) { | ||||||
| 			if (shortcut) { | 			if (shortcut && !shortcut.startsWith("global:")) { // global shortcuts should be handled in the electron code | ||||||
| 				utils.bindGlobalShortcut(shortcut, handler); | 				utils.bindGlobalShortcut(shortcut, handler); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @@ -80,7 +56,7 @@ function setElementActionHandler($el, actionName, handler) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function triggerAction(actionName) { | async function triggerAction(actionName) { | ||||||
| 	const action = getAction(actionName); | 	const action = await getAction(actionName); | ||||||
|  |  | ||||||
| 	if (!action.handler) { | 	if (!action.handler) { | ||||||
| 		throw new Error(`Action ${actionName} has no handler`); | 		throw new Error(`Action ${actionName} has no handler`); | ||||||
|   | |||||||
| @@ -72,7 +72,7 @@ function goToLink(e) { | |||||||
|  |  | ||||||
|     if (notePath) { |     if (notePath) { | ||||||
|         if ((e.which === 1 && e.ctrlKey) || e.which === 2) { |         if ((e.which === 1 && e.ctrlKey) || e.which === 2) { | ||||||
|             noteDetailService.openInTab(notePath); |             noteDetailService.openInTab(notePath, false); | ||||||
|         } |         } | ||||||
|         else if (e.which === 1) { |         else if (e.which === 1) { | ||||||
|             treeService.activateNote(notePath); |             treeService.activateNote(notePath); | ||||||
|   | |||||||
| @@ -35,8 +35,8 @@ async function reloadAllTabs() { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function openInTab(notePath) { | async function openInTab(notePath, activate) { | ||||||
|     await loadNoteDetail(notePath, { newTab: true }); |     await loadNoteDetail(notePath, { newTab: true, activate }); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function switchToNote(notePath) { | async function switchToNote(notePath) { | ||||||
|   | |||||||
| @@ -159,7 +159,7 @@ class NoteDetailRelationMap { | |||||||
|         const noteId = this.idToNoteId($noteBox.prop("id")); |         const noteId = this.idToNoteId($noteBox.prop("id")); | ||||||
|  |  | ||||||
|         if (cmd === "open-in-new-tab") { |         if (cmd === "open-in-new-tab") { | ||||||
|             noteDetailService.openInTab(noteId); |             noteDetailService.openInTab(noteId, false); | ||||||
|         } |         } | ||||||
|         else if (cmd === "remove") { |         else if (cmd === "remove") { | ||||||
|             const confirmDialog = await import('../dialogs/confirm.js'); |             const confirmDialog = await import('../dialogs/confirm.js'); | ||||||
|   | |||||||
| @@ -626,6 +626,8 @@ async function createNewTopLevelNote() { | |||||||
| async function createNote(node, parentNoteId, target, extraOptions = {}) { | async function createNote(node, parentNoteId, target, extraOptions = {}) { | ||||||
|     utils.assertArguments(node, parentNoteId, target); |     utils.assertArguments(node, parentNoteId, target); | ||||||
|  |  | ||||||
|  |     extraOptions.activate = extraOptions.activate === undefined ? true : !!extraOptions.activate; | ||||||
|  |  | ||||||
|     // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted |     // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted | ||||||
|     // but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often |     // but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often | ||||||
|     if (!extraOptions.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()) { |     if (!extraOptions.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()) { | ||||||
| @@ -667,7 +669,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { | |||||||
|     const noteEntity = await treeCache.getNote(note.noteId); |     const noteEntity = await treeCache.getNote(note.noteId); | ||||||
|     const branchEntity = treeCache.getBranch(branch.branchId); |     const branchEntity = treeCache.getBranch(branch.branchId); | ||||||
|  |  | ||||||
|     let newNode = { |     let newNodeData = { | ||||||
|         title: newNoteName, |         title: newNoteName, | ||||||
|         noteId: branchEntity.noteId, |         noteId: branchEntity.noteId, | ||||||
|         parentNoteId: parentNoteId, |         parentNoteId: parentNoteId, | ||||||
| @@ -682,8 +684,11 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { | |||||||
|         key: utils.randomString(12) // this should prevent some "duplicate key" errors |         key: utils.randomString(12) // this should prevent some "duplicate key" errors | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     /** @var {FancytreeNode} */ | ||||||
|  |     let newNode; | ||||||
|  |  | ||||||
|     if (target === 'after') { |     if (target === 'after') { | ||||||
|         await node.appendSibling(newNode).setActive(true); |         newNode = node.appendSibling(newNodeData); | ||||||
|     } |     } | ||||||
|     else if (target === 'into') { |     else if (target === 'into') { | ||||||
|         if (!node.getChildren() && node.isFolder()) { |         if (!node.getChildren() && node.isFolder()) { | ||||||
| @@ -693,10 +698,10 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { | |||||||
|             await node.setExpanded(); |             await node.setExpanded(); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             node.addChildren(newNode); |             node.addChildren(newNodeData); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         await node.getLastChild().setActive(true); |         newNode = node.getLastChild(); | ||||||
|  |  | ||||||
|         const parentNoteEntity = await treeCache.getNote(node.data.noteId); |         const parentNoteEntity = await treeCache.getNote(node.data.noteId); | ||||||
|  |  | ||||||
| @@ -708,14 +713,18 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { | |||||||
|         toastService.throwError("Unrecognized target: " + target); |         toastService.throwError("Unrecognized target: " + target); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     if (extraOptions.activate) { | ||||||
|  |         await newNode.setActive(true); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     clearSelectedNodes(); // to unmark previously active node |     clearSelectedNodes(); // to unmark previously active node | ||||||
|  |  | ||||||
|     // need to refresh because original doesn't have methods like .getParent() |     // need to refresh because original doesn't have methods like .getParent() | ||||||
|     newNode = getNodesByNoteId(branchEntity.noteId)[0]; |     newNodeData = getNodesByNoteId(branchEntity.noteId)[0]; | ||||||
|  |  | ||||||
|     // following for cycle will make sure that also clones of a parent are refreshed |     // following for cycle will make sure that also clones of a parent are refreshed | ||||||
|     for (const newParentNode of getNodesByNoteId(parentNoteId)) { |     for (const newParentNode of getNodesByNoteId(parentNoteId)) { | ||||||
|         if (newParentNode.key === newNode.getParent().key) { |         if (newParentNode.key === newNodeData.getParent().key) { | ||||||
|             // we've added a note into this one so no need to refresh |             // we've added a note into this one so no need to refresh | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
| @@ -887,7 +896,7 @@ $tree.on('mousedown', '.fancytree-title', e => { | |||||||
|  |  | ||||||
|         treeUtils.getNotePath(node).then(notePath => { |         treeUtils.getNotePath(node).then(notePath => { | ||||||
|             if (notePath) { |             if (notePath) { | ||||||
|                 noteDetailService.openInTab(notePath); |                 noteDetailService.openInTab(notePath, false); | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -97,7 +97,7 @@ class TreeContextMenu { | |||||||
|         if (cmd === 'openInTab') { |         if (cmd === 'openInTab') { | ||||||
|             const notePath = await treeUtils.getNotePath(this.node); |             const notePath = await treeUtils.getNotePath(this.node); | ||||||
|  |  | ||||||
|             noteDetailService.openInTab(notePath); |             noteDetailService.openInTab(notePath, false); | ||||||
|         } |         } | ||||||
|         else if (cmd.startsWith("insertNoteAfter")) { |         else if (cmd.startsWith("insertNoteAfter")) { | ||||||
|             const parentNoteId = this.node.data.parentNoteId; |             const parentNoteId = this.node.data.parentNoteId; | ||||||
|   | |||||||
| @@ -48,14 +48,10 @@ const DEFAULT_KEYBOARD_ACTIONS = [ | |||||||
|         defaultShortcuts: ["Alt+-"], |         defaultShortcuts: ["Alt+-"], | ||||||
|         description: "Collapses subtree of current note" |         description: "Collapses subtree of current note" | ||||||
|     }, |     }, | ||||||
|     { |  | ||||||
|         actionName: "FocusNote", |  | ||||||
|         defaultShortcuts: ["Enter"] |  | ||||||
|     }, |  | ||||||
|     { |     { | ||||||
|         actionName: "ActivateParentNote", |         actionName: "ActivateParentNote", | ||||||
|         defaultShortcuts: ["Backspace"], |         defaultShortcuts: ["Backspace"], | ||||||
|         description: "Activates parent note of currently active note" |         description: "Activates the parent note of currently active note" | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|         actionName: "SortChildNotes", |         actionName: "SortChildNotes", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user