mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	better UX when deleting notes - focus in note tree is moved to the next/previous note
This commit is contained in:
		| @@ -37,6 +37,10 @@ function subscribeToMessages(messageHandler) { | ||||
| // used to serialize sync operations | ||||
| let consumeQueuePromise = null; | ||||
|  | ||||
| // most sync events are sent twice - once immediatelly after finishing the transaction and once during the scheduled ping | ||||
| // but we want to process only once | ||||
| const receivedSyncIds = new Set(); | ||||
|  | ||||
| async function handleMessage(event) { | ||||
|     const message = JSON.parse(event.data); | ||||
|  | ||||
| @@ -52,14 +56,19 @@ async function handleMessage(event) { | ||||
|  | ||||
|         if (syncRows.length > 0) { | ||||
|             const filteredRows = syncRows.filter(row => | ||||
|                 row.entityName !== 'recent_notes' | ||||
|                 !receivedSyncIds.has(row.id) | ||||
|                 && row.entityName !== 'recent_notes' | ||||
|                 && (row.entityName !== 'options' || row.entityId !== 'openTabs')); | ||||
|  | ||||
|             if (filteredRows.length > 0) { | ||||
|                 console.debug(utils.now(), "Sync data: ", filteredRows); | ||||
|             } | ||||
|  | ||||
|             syncDataQueue.push(...syncRows); | ||||
|             for (const row of filteredRows) { | ||||
|                 receivedSyncIds.add(row.id); | ||||
|             } | ||||
|  | ||||
|             syncDataQueue.push(...filteredRows); | ||||
|  | ||||
|             // we set lastAcceptedSyncId even before sync processing and send ping so that backend can start sending more updates | ||||
|             lastAcceptedSyncId = Math.max(lastAcceptedSyncId, syncRows[syncRows.length - 1].id); | ||||
|   | ||||
| @@ -804,7 +804,9 @@ export default class NoteTreeWidget extends TabAwareWidget { | ||||
|  | ||||
|     async entitiesReloadedEvent({loadResults}) { | ||||
|         const activeNode = this.getActiveNode(); | ||||
|         const nextNode = activeNode ? (activeNode.getNextSibling() || activeNode.getPrevSibling() || activeNode.getParent()) : null; | ||||
|         const activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null; | ||||
|         const nextNotePath = nextNode ? treeService.getNotePath(nextNode) : null; | ||||
|         const activeNoteId = activeNode ? activeNode.data.noteId : null; | ||||
|  | ||||
|         const noteIdsToUpdate = new Set(); | ||||
| @@ -926,6 +928,17 @@ export default class NoteTreeWidget extends TabAwareWidget { | ||||
|             if (node) { | ||||
|                 node.setActive(true, {noEvents: true}); | ||||
|             } | ||||
|             else { | ||||
|                 // this is used when original note has been deleted and we want to move the focus to the note above/below | ||||
|                 node = await this.expandToNote(nextNotePath); | ||||
|  | ||||
|                 if (node) { | ||||
|                     this.tree.setFocus(); | ||||
|                     node.setFocus(true); | ||||
|  | ||||
|                     await appContext.tabManager.getActiveTabContext().setNote(nextNotePath); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -614,6 +614,7 @@ export default class TabRowWidget extends BasicWidget { | ||||
|  | ||||
|         if (!note) { | ||||
|             this.updateTitle($tab, 'New tab'); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         this.updateTitle($tab, note.title); | ||||
|   | ||||
| @@ -221,6 +221,7 @@ async function transactional(func) { | ||||
|  | ||||
|             await commit(); | ||||
|  | ||||
|             // note that sync rows sent from this action will be sent again by scheduled periodic ping | ||||
|             require('./ws.js').sendPingToAllClients(); | ||||
|  | ||||
|             transactionActive = false; | ||||
| @@ -267,4 +268,4 @@ module.exports = { | ||||
|     executeScript, | ||||
|     transactional, | ||||
|     upsert | ||||
| }; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user