mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 17:38:47 +02:00
fix bug when context menu sometimes does not show up, closes #682
This commit is contained in:
parent
b67aa99b86
commit
df40accdd4
@ -26,9 +26,7 @@ async function moveBeforeNode(nodesToMove, beforeNode) {
|
||||
|
||||
await changeNode(
|
||||
node => node.moveTo(beforeNode, 'before'),
|
||||
nodeToMove,
|
||||
beforeNode.data.noteId,
|
||||
null);
|
||||
nodeToMove);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,9 +50,7 @@ async function moveAfterNode(nodesToMove, afterNode) {
|
||||
|
||||
await changeNode(
|
||||
node => node.moveTo(afterNode, 'after'),
|
||||
nodeToMove,
|
||||
null,
|
||||
afterNode.data.noteId);
|
||||
nodeToMove);
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +173,7 @@ async function moveNodeUpInHierarchy(node) {
|
||||
node);
|
||||
}
|
||||
|
||||
async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
|
||||
async function changeNode(func, node) {
|
||||
utils.assertArguments(func, node);
|
||||
|
||||
const childNoteId = node.data.noteId;
|
||||
|
@ -1,6 +1,4 @@
|
||||
import utils from "./utils.js";
|
||||
import Branch from "../entities/branch.js";
|
||||
import server from "./server.js";
|
||||
import treeCache from "./tree_cache.js";
|
||||
import ws from "./ws.js";
|
||||
import hoistedNoteService from "./hoisted_note.js";
|
||||
@ -110,24 +108,8 @@ async function prepareRealBranch(parentNote) {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return await prepareRealBranch(newNote);
|
||||
|
@ -102,6 +102,35 @@ class TreeCache {
|
||||
const resp = await server.post('tree/load', { noteIds });
|
||||
|
||||
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[]>} */
|
||||
@ -109,9 +138,7 @@ class TreeCache {
|
||||
const missingNoteIds = noteIds.filter(noteId => this.notes[noteId] === undefined);
|
||||
|
||||
if (missingNoteIds.length > 0) {
|
||||
const resp = await server.post('tree/load', { noteIds: missingNoteIds });
|
||||
|
||||
this.addResp(resp.notes, resp.branches);
|
||||
await this.reloadNotes(missingNoteIds);
|
||||
}
|
||||
|
||||
return noteIds.map(noteId => {
|
||||
|
@ -26,8 +26,8 @@ class TreeContextMenu {
|
||||
}
|
||||
|
||||
async getContextMenuItems() {
|
||||
const branch = treeCache.getBranch(this.node.data.branchId);
|
||||
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 isNotRoot = note.noteId !== 'root';
|
||||
const isHoisted = note.noteId === await hoistedNoteService.getHoistedNoteId();
|
||||
@ -39,9 +39,9 @@ class TreeContextMenu {
|
||||
const noSelectedNotes = selNodes.length === 0
|
||||
|| (selNodes.length === 1 && selNodes[0] === this.node);
|
||||
|
||||
const notSearch = note.type !== 'search';
|
||||
const parentNotSearch = parentNote.type !== 'search';
|
||||
const insertNoteAfterEnabled = isNotRoot && !isHoisted && parentNotSearch;
|
||||
const notSearch = note.type !== 'search';
|
||||
|
||||
return [
|
||||
{ title: "Open in new tab", cmd: "openInTab", uiIcon: "empty", enabled: noSelectedNotes },
|
||||
|
Loading…
x
Reference in New Issue
Block a user