mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fix bug when context menu sometimes does not show up, closes #682
This commit is contained in:
		| @@ -26,9 +26,7 @@ async function moveBeforeNode(nodesToMove, beforeNode) { | |||||||
|  |  | ||||||
|         await changeNode( |         await changeNode( | ||||||
|             node => node.moveTo(beforeNode, 'before'), |             node => node.moveTo(beforeNode, 'before'), | ||||||
|             nodeToMove, |             nodeToMove); | ||||||
|             beforeNode.data.noteId, |  | ||||||
|             null); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -52,9 +50,7 @@ async function moveAfterNode(nodesToMove, afterNode) { | |||||||
|  |  | ||||||
|         await changeNode( |         await changeNode( | ||||||
|             node => node.moveTo(afterNode, 'after'), |             node => node.moveTo(afterNode, 'after'), | ||||||
|             nodeToMove, |             nodeToMove); | ||||||
|             null, |  | ||||||
|             afterNode.data.noteId); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -177,7 +173,7 @@ async function moveNodeUpInHierarchy(node) { | |||||||
|         node); |         node); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) { | async function changeNode(func, node) { | ||||||
|     utils.assertArguments(func, node); |     utils.assertArguments(func, node); | ||||||
|  |  | ||||||
|     const childNoteId = node.data.noteId; |     const childNoteId = node.data.noteId; | ||||||
|   | |||||||
| @@ -1,6 +1,4 @@ | |||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
| import Branch from "../entities/branch.js"; |  | ||||||
| import server from "./server.js"; |  | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| import ws from "./ws.js"; | import ws from "./ws.js"; | ||||||
| import hoistedNoteService from "./hoisted_note.js"; | import hoistedNoteService from "./hoisted_note.js"; | ||||||
| @@ -110,24 +108,8 @@ async function prepareRealBranch(parentNote) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function prepareSearchBranch(note) { | async function prepareSearchBranch(note) { | ||||||
|     const results = await server.get('search-note/' + note.noteId); |     await treeCache.reloadNotes([note.noteId]); | ||||||
|  |  | ||||||
|     // force to load all the notes at once instead of one by one |  | ||||||
|     await treeCache.getNotes(results.map(res => res.noteId)); |  | ||||||
|  |  | ||||||
|     const {notes, branches} = await server.post('tree/load', { noteIds: [note.noteId] }); |  | ||||||
|  |  | ||||||
|     results.forEach((result, index) => branches.push({ |  | ||||||
|         branchId: "virt" + utils.randomString(10), |  | ||||||
|         noteId: result.noteId, |  | ||||||
|         parentNoteId: note.noteId, |  | ||||||
|         prefix: treeCache.getBranch(result.branchId).prefix, |  | ||||||
|         notePosition: (index + 1) * 10 |  | ||||||
|     })); |  | ||||||
|  |  | ||||||
|     treeCache.addResp(notes, branches); |  | ||||||
|  |  | ||||||
|     // note in cache changed |  | ||||||
|     const newNote = await treeCache.getNote(note.noteId); |     const newNote = await treeCache.getNote(note.noteId); | ||||||
|  |  | ||||||
|     return await prepareRealBranch(newNote); |     return await prepareRealBranch(newNote); | ||||||
|   | |||||||
| @@ -102,6 +102,35 @@ class TreeCache { | |||||||
|         const resp = await server.post('tree/load', { noteIds }); |         const resp = await server.post('tree/load', { noteIds }); | ||||||
|  |  | ||||||
|         this.addResp(resp.notes, resp.branches); |         this.addResp(resp.notes, resp.branches); | ||||||
|  |  | ||||||
|  |         for (const note of resp.notes) { | ||||||
|  |             if (note.type === 'search') { | ||||||
|  |                 const someExpanded = resp.branches.find(b => b.noteId === note.noteId && b.isExpanded); | ||||||
|  |  | ||||||
|  |                 if (!someExpanded) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 const searchResults = await server.get('search-note/' + note.noteId); | ||||||
|  |  | ||||||
|  |                 // force to load all the notes at once instead of one by one | ||||||
|  |                 await treeCache.getNotes(searchResults.map(res => res.noteId)); | ||||||
|  |  | ||||||
|  |                 const branches = resp.branches.filter(b => b.noteId === note.noteId || b.parentNoteId === note.noteId); | ||||||
|  |  | ||||||
|  |                 searchResults.forEach((result, index) => branches.push({ | ||||||
|  |                     // branchId should be repeatable since sometimes we reload some notes without rerendering the tree | ||||||
|  |                     branchId: "virt" + result.noteId + '-' + note.noteId, | ||||||
|  |                     noteId: result.noteId, | ||||||
|  |                     parentNoteId: note.noteId, | ||||||
|  |                     prefix: treeCache.getBranch(result.branchId).prefix, | ||||||
|  |                     notePosition: (index + 1) * 10 | ||||||
|  |                 })); | ||||||
|  |  | ||||||
|  |                 // update this note with standard (parent) branches + virtual (children) branches | ||||||
|  |                 treeCache.addResp([note], branches); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @return {Promise<NoteShort[]>} */ |     /** @return {Promise<NoteShort[]>} */ | ||||||
| @@ -109,9 +138,7 @@ class TreeCache { | |||||||
|         const missingNoteIds = noteIds.filter(noteId => this.notes[noteId] === undefined); |         const missingNoteIds = noteIds.filter(noteId => this.notes[noteId] === undefined); | ||||||
|  |  | ||||||
|         if (missingNoteIds.length > 0) { |         if (missingNoteIds.length > 0) { | ||||||
|             const resp = await server.post('tree/load', { noteIds: missingNoteIds }); |             await this.reloadNotes(missingNoteIds); | ||||||
|  |  | ||||||
|             this.addResp(resp.notes, resp.branches); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return noteIds.map(noteId => { |         return noteIds.map(noteId => { | ||||||
|   | |||||||
| @@ -26,8 +26,8 @@ class TreeContextMenu { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getContextMenuItems() { |     async getContextMenuItems() { | ||||||
|         const branch = treeCache.getBranch(this.node.data.branchId); |  | ||||||
|         const note = await treeCache.getNote(this.node.data.noteId); |         const note = await treeCache.getNote(this.node.data.noteId); | ||||||
|  |         const branch = treeCache.getBranch(this.node.data.branchId); | ||||||
|         const parentNote = await treeCache.getNote(branch.parentNoteId); |         const parentNote = await treeCache.getNote(branch.parentNoteId); | ||||||
|         const isNotRoot = note.noteId !== 'root'; |         const isNotRoot = note.noteId !== 'root'; | ||||||
|         const isHoisted = note.noteId === await hoistedNoteService.getHoistedNoteId(); |         const isHoisted = note.noteId === await hoistedNoteService.getHoistedNoteId(); | ||||||
| @@ -39,9 +39,9 @@ class TreeContextMenu { | |||||||
|         const noSelectedNotes = selNodes.length === 0 |         const noSelectedNotes = selNodes.length === 0 | ||||||
|                 || (selNodes.length === 1 && selNodes[0] === this.node); |                 || (selNodes.length === 1 && selNodes[0] === this.node); | ||||||
|  |  | ||||||
|  |         const notSearch = note.type !== 'search'; | ||||||
|         const parentNotSearch = parentNote.type !== 'search'; |         const parentNotSearch = parentNote.type !== 'search'; | ||||||
|         const insertNoteAfterEnabled = isNotRoot && !isHoisted && parentNotSearch; |         const insertNoteAfterEnabled = isNotRoot && !isHoisted && parentNotSearch; | ||||||
|         const notSearch = note.type !== 'search'; |  | ||||||
|  |  | ||||||
|         return [ |         return [ | ||||||
|             { title: "Open in new tab", cmd: "openInTab", uiIcon: "empty", enabled: noSelectedNotes }, |             { title: "Open in new tab", cmd: "openInTab", uiIcon: "empty", enabled: noSelectedNotes }, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user