mirror of
https://github.com/zadam/trilium.git
synced 2025-02-22 14:03:36 +08:00
tree reloads should preserve activated node, fixes #552
This commit is contained in:
parent
d08a36174d
commit
74b41c9911
1 changed files with 8 additions and 15 deletions
|
@ -369,8 +369,6 @@ async function treeInitialized() {
|
||||||
setFrontendAsLoaded();
|
setFrontendAsLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
let ignoreNextActivationNoteId = null;
|
|
||||||
|
|
||||||
function initFancyTree(tree) {
|
function initFancyTree(tree) {
|
||||||
utils.assertArguments(tree);
|
utils.assertArguments(tree);
|
||||||
|
|
||||||
|
@ -402,16 +400,6 @@ function initFancyTree(tree) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeActivate: (event, data) => {
|
|
||||||
// make sure the reload won't trigger reactivation.
|
|
||||||
// This is important especially in cases where we wait for the reload to finish to then activate some other note.
|
|
||||||
// But since the activate() event is called asynchronously, it may be called (or finished calling)
|
|
||||||
// after we switched to a different note so it's not possible to just check if current note matches requested note
|
|
||||||
if (ignoreNextActivationNoteId && getActiveNode() !== null && getActiveNode().data.noteId === data.node.data.noteId) {
|
|
||||||
ignoreNextActivationNoteId = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
activate: async (event, data) => {
|
activate: async (event, data) => {
|
||||||
// click event won't propagate so let's close context menu manually
|
// click event won't propagate so let's close context menu manually
|
||||||
contextMenuWidget.hideContextMenu();
|
contextMenuWidget.hideContextMenu();
|
||||||
|
@ -490,11 +478,16 @@ function getTree() {
|
||||||
async function reload() {
|
async function reload() {
|
||||||
const notes = await loadTree();
|
const notes = await loadTree();
|
||||||
|
|
||||||
if (getActiveNode()) {
|
const activeNotePath = getActiveNode() !== null ? await treeUtils.getNotePath(getActiveNode()) : null;
|
||||||
ignoreNextActivationNoteId = getActiveNode().data.noteId;
|
|
||||||
}
|
|
||||||
|
|
||||||
await getTree().reload(notes);
|
await getTree().reload(notes);
|
||||||
|
|
||||||
|
// reactivate originally activated node, but don't trigger note loading
|
||||||
|
if (activeNotePath) {
|
||||||
|
const node = await getNodeFromPath(activeNotePath, true);
|
||||||
|
|
||||||
|
await node.setActive(true, {noEvents: true});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNotePathInAddress() {
|
function isNotePathInAddress() {
|
||||||
|
|
Loading…
Reference in a new issue