mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
Merge pull request #3837 from soulsands/fix-tree
fix: correct moving active node
This commit is contained in:
commit
9a22c3fce7
@ -223,7 +223,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$treeSettingsPopup.on("click", e => { e.stopPropagation(); });
|
this.$treeSettingsPopup.on("click", e => {e.stopPropagation();});
|
||||||
|
|
||||||
$(document).on('click', () => this.$treeSettingsPopup.hide());
|
$(document).on('click', () => this.$treeSettingsPopup.hide());
|
||||||
|
|
||||||
@ -251,12 +251,12 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
// code inspired by https://gist.github.com/jtsternberg/c272d7de5b967cec2d3d
|
// code inspired by https://gist.github.com/jtsternberg/c272d7de5b967cec2d3d
|
||||||
const isEnclosing = ($container, $sub) => {
|
const isEnclosing = ($container, $sub) => {
|
||||||
const conOffset = $container.offset();
|
const conOffset = $container.offset();
|
||||||
const conDistanceFromTop = conOffset.top + $container.outerHeight(true);
|
const conDistanceFromTop = conOffset.top + $container.outerHeight(true);
|
||||||
const conDistanceFromLeft = conOffset.left + $container.outerWidth(true);
|
const conDistanceFromLeft = conOffset.left + $container.outerWidth(true);
|
||||||
|
|
||||||
const subOffset = $sub.offset();
|
const subOffset = $sub.offset();
|
||||||
const subDistanceFromTop = subOffset.top + $sub.outerHeight(true);
|
const subDistanceFromTop = subOffset.top + $sub.outerHeight(true);
|
||||||
const subDistanceFromLeft = subOffset.left + $sub.outerWidth(true);
|
const subDistanceFromLeft = subOffset.left + $sub.outerWidth(true);
|
||||||
|
|
||||||
return conDistanceFromTop > subDistanceFromTop
|
return conDistanceFromTop > subDistanceFromTop
|
||||||
@ -673,7 +673,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
return noteList;
|
return noteList;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateNode(node) {
|
async updateNode(node) {
|
||||||
const note = froca.getNoteFromCache(node.data.noteId);
|
const note = froca.getNoteFromCache(node.data.noteId);
|
||||||
const branch = froca.getBranch(node.data.branchId);
|
const branch = froca.getBranch(node.data.branchId);
|
||||||
|
|
||||||
@ -697,7 +697,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
node.title = utils.escapeHtml(title);
|
node.title = utils.escapeHtml(title);
|
||||||
|
|
||||||
if (node.isExpanded() !== branch.isExpanded) {
|
if (node.isExpanded() !== branch.isExpanded) {
|
||||||
node.setExpanded(branch.isExpanded, {noEvents: true, noAnimation: true});
|
await node.setExpanded(branch.isExpanded, {noEvents: true, noAnimation: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
node.renderTitle();
|
node.renderTitle();
|
||||||
@ -849,7 +849,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
await this.setExpandedStatusForSubtree(node, false);
|
await this.setExpandedStatusForSubtree(node, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
collapseTreeEvent() { this.collapseTree(); }
|
collapseTreeEvent() {this.collapseTree();}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {FancytreeNode|null}
|
* @returns {FancytreeNode|null}
|
||||||
@ -920,7 +920,9 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (expand) {
|
if (expand) {
|
||||||
await parentNode.setExpanded(true, {noAnimation: true});
|
if (!parentNode.isExpanded()) {
|
||||||
|
await parentNode.setExpanded(true, {noAnimation: true});
|
||||||
|
}
|
||||||
|
|
||||||
// although previous line should set the expanded status, it seems to happen asynchronously,
|
// although previous line should set the expanded status, it seems to happen asynchronously,
|
||||||
// so we need to make sure it is set properly before calling updateNode which uses this flag
|
// so we need to make sure it is set properly before calling updateNode which uses this flag
|
||||||
@ -928,7 +930,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
branch.isExpanded = true;
|
branch.isExpanded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateNode(parentNode);
|
await this.updateNode(parentNode);
|
||||||
|
|
||||||
let foundChildNode = this.findChildNode(parentNode, childNoteId);
|
let foundChildNode = this.findChildNode(parentNode, childNoteId);
|
||||||
|
|
||||||
@ -1096,10 +1098,10 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
const activeNode = this.getActiveNode();
|
const activeNode = this.getActiveNode();
|
||||||
const activeNodeFocused = activeNode && activeNode.hasFocus();
|
const activeNodeFocused = activeNode && activeNode.hasFocus();
|
||||||
const nextNode = activeNode ? (activeNode.getNextSibling() || activeNode.getPrevSibling() || activeNode.getParent()) : null;
|
const nextNode = activeNode ? (activeNode.getNextSibling() || activeNode.getPrevSibling() || activeNode.getParent()) : null;
|
||||||
const activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null;
|
let activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null;
|
||||||
|
|
||||||
const nextNotePath = nextNode ? treeService.getNotePath(nextNode) : null;
|
const nextNotePath = nextNode ? treeService.getNotePath(nextNode) : null;
|
||||||
const activeNoteId = activeNode ? activeNode.data.noteId : null;
|
let activeNoteId = activeNode ? activeNode.data.noteId : null;
|
||||||
|
|
||||||
const noteIdsToUpdate = new Set();
|
const noteIdsToUpdate = new Set();
|
||||||
const noteIdsToReload = new Set();
|
const noteIdsToReload = new Set();
|
||||||
@ -1142,7 +1144,14 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const ecBranch of loadResults.getBranches()) {
|
// activeNode is supposed to be moved when we find out activeNode is deleted but not all branches are deleted. save it for fixing activeNodePath after all nodes loaded.
|
||||||
|
let movedActiveNode = null;
|
||||||
|
let parentsOfAddedNodes = [];
|
||||||
|
|
||||||
|
const allBranches = loadResults.getBranches();
|
||||||
|
const allBranchesDeleted = allBranches.every(branch => !!branch.isDeleted);
|
||||||
|
|
||||||
|
for (const ecBranch of allBranches) {
|
||||||
if (ecBranch.parentNoteId === '_share') {
|
if (ecBranch.parentNoteId === '_share') {
|
||||||
// all shared notes have a sign in the tree, even the descendants of shared notes
|
// all shared notes have a sign in the tree, even the descendants of shared notes
|
||||||
noteIdsToReload.add(ecBranch.noteId);
|
noteIdsToReload.add(ecBranch.noteId);
|
||||||
@ -1155,12 +1164,16 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
for (const node of this.getNodesByBranch(ecBranch)) {
|
for (const node of this.getNodesByBranch(ecBranch)) {
|
||||||
if (ecBranch.isDeleted) {
|
if (ecBranch.isDeleted) {
|
||||||
if (node.isActive()) {
|
if (node.isActive()) {
|
||||||
const newActiveNode = node.getNextSibling()
|
if (allBranchesDeleted) {
|
||||||
|| node.getPrevSibling()
|
const newActiveNode = node.getNextSibling()
|
||||||
|| node.getParent();
|
|| node.getPrevSibling()
|
||||||
|
|| node.getParent();
|
||||||
|
|
||||||
if (newActiveNode) {
|
if (newActiveNode) {
|
||||||
newActiveNode.setActive(true, {noEvents: true, noFocus: true});
|
newActiveNode.setActive(true, {noEvents: true, noFocus: true});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
movedActiveNode = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1174,12 +1187,13 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
if (!ecBranch.isDeleted) {
|
if (!ecBranch.isDeleted) {
|
||||||
for (const parentNode of this.getNodesByNoteId(ecBranch.parentNoteId)) {
|
for (const parentNode of this.getNodesByNoteId(ecBranch.parentNoteId)) {
|
||||||
|
parentsOfAddedNodes.push(parentNode)
|
||||||
|
|
||||||
if (parentNode.isFolder() && !parentNode.isLoaded()) {
|
if (parentNode.isFolder() && !parentNode.isLoaded()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const found = (parentNode.getChildren() || []).find(child => child.data.noteId === ecBranch.noteId);
|
const found = (parentNode.getChildren() || []).find(child => child.data.noteId === ecBranch.noteId);
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
// make sure it's loaded
|
// make sure it's loaded
|
||||||
await froca.getNote(ecBranch.noteId);
|
await froca.getNote(ecBranch.noteId);
|
||||||
@ -1222,7 +1236,18 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
// for some reason node update cannot be in the batchUpdate() block (node is not re-rendered)
|
// for some reason node update cannot be in the batchUpdate() block (node is not re-rendered)
|
||||||
for (const noteId of noteIdsToUpdate) {
|
for (const noteId of noteIdsToUpdate) {
|
||||||
for (const node of this.getNodesByNoteId(noteId)) {
|
for (const node of this.getNodesByNoteId(noteId)) {
|
||||||
this.updateNode(node);
|
await this.updateNode(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movedActiveNode) {
|
||||||
|
for (const parentNode of parentsOfAddedNodes) {
|
||||||
|
const found = (parentNode.getChildren() || []).find(child => child.data.noteId === movedActiveNode.data.noteId);
|
||||||
|
if (found) {
|
||||||
|
activeNotePath = treeService.getNotePath(found);
|
||||||
|
activeNoteId = found.data.noteId;
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user