mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes for some note moving edge cases, closes #454
This commit is contained in:
parent
33f2aaa650
commit
1faf2c6ecd
@ -20,7 +20,11 @@ async function moveBeforeNode(nodesToMove, beforeNode) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await changeNode(nodeToMove, node => node.moveTo(beforeNode, 'before'));
|
await changeNode(
|
||||||
|
node => node.moveTo(beforeNode, 'before'),
|
||||||
|
nodeToMove,
|
||||||
|
beforeNode.data.noteId,
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +46,11 @@ async function moveAfterNode(nodesToMove, afterNode) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await changeNode(nodeToMove, node => node.moveTo(afterNode, 'after'));
|
await changeNode(
|
||||||
|
node => node.moveTo(afterNode, 'after'),
|
||||||
|
nodeToMove,
|
||||||
|
null,
|
||||||
|
afterNode.data.noteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,20 +65,14 @@ async function moveToNode(nodesToMove, toNode) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await changeNode(nodeToMove, async node => {
|
await changeNode(async node => {
|
||||||
// first expand which will force lazy load and only then move the node
|
// first expand which will force lazy load and only then move the node
|
||||||
// if this is not expanded before moving, then lazy load won't happen because it already contains node
|
// if this is not expanded before moving, then lazy load won't happen because it already contains node
|
||||||
// this doesn't work if this isn't a folder yet, that's why we expand second time below
|
// this doesn't work if this isn't a folder yet, that's why we expand second time below
|
||||||
await toNode.setExpanded(true);
|
await toNode.setExpanded(true);
|
||||||
|
|
||||||
node.moveTo(toNode);
|
node.moveTo(toNode);
|
||||||
|
}, nodeToMove);
|
||||||
toNode.folder = true;
|
|
||||||
toNode.renderTitle();
|
|
||||||
|
|
||||||
// this expands the note in case it become the folder only after the move
|
|
||||||
await toNode.setExpanded(true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,22 +133,72 @@ async function moveNodeUpInHierarchy(node) {
|
|||||||
node.getParent().renderTitle();
|
node.getParent().renderTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
await changeNode(node, node => node.moveTo(node.getParent(), 'after'));
|
await changeNode(
|
||||||
|
node => node.moveTo(node.getParent(), 'after'),
|
||||||
|
node);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changeNode(node, func) {
|
async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
|
||||||
utils.assertArguments(node.data.parentNoteId, node.data.noteId);
|
utils.assertArguments(func, node);
|
||||||
|
|
||||||
const childNoteId = node.data.noteId;
|
const childNoteId = node.data.noteId;
|
||||||
const oldParentNoteId = node.data.parentNoteId;
|
const thisOldParentNode = node.getParent();
|
||||||
|
|
||||||
|
// this will move the node the user is directly operating on to the desired location
|
||||||
|
// note that there might be other instances of this note in the tree and those are updated through
|
||||||
|
// force reloading. We could simplify our lives by just reloading this one as well, but that leads
|
||||||
|
// to flickering and not good user experience. Current solution leads to no-flicker experience in most
|
||||||
|
// cases (since cloning is not used that often) and correct for multi-clone use cases
|
||||||
await func(node);
|
await func(node);
|
||||||
|
|
||||||
const newParentNoteId = node.data.parentNoteId = utils.isTopLevelNode(node) ? 'root' : node.getParent().data.noteId;
|
const thisNewParentNode = node.getParent();
|
||||||
|
|
||||||
await treeCache.moveNote(childNoteId, oldParentNoteId, newParentNoteId);
|
node.data.parentNoteId = thisNewParentNode.data.noteId;
|
||||||
|
|
||||||
|
await treeCache.moveNote(childNoteId, thisOldParentNode.data.noteId, thisNewParentNode.data.noteId, beforeNoteId, afterNoteId);
|
||||||
|
|
||||||
treeService.setCurrentNotePathToHash(node);
|
treeService.setCurrentNotePathToHash(node);
|
||||||
|
|
||||||
|
if (!thisOldParentNode.getChildren() || thisOldParentNode.getChildren().length === 0) {
|
||||||
|
thisOldParentNode.folder = false;
|
||||||
|
thisOldParentNode.renderTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!thisNewParentNode.folder) {
|
||||||
|
thisNewParentNode.folder = true;
|
||||||
|
thisNewParentNode.renderTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!thisNewParentNode.isExpanded()) {
|
||||||
|
// this expands the note in case it become the folder only after the move
|
||||||
|
await thisNewParentNode.setExpanded(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const newParentNode of treeService.getNodesByNoteId(thisNewParentNode.data.noteId)) {
|
||||||
|
if (newParentNode.key === thisNewParentNode.key) {
|
||||||
|
// this one has been handled above specifically
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
newParentNode.load(true); // force reload to show up new note
|
||||||
|
newParentNode.folder = true;
|
||||||
|
newParentNode.renderTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const oldParentNode of treeService.getNodesByNoteId(thisOldParentNode.data.noteId)) {
|
||||||
|
if (oldParentNode.key === thisOldParentNode.key) {
|
||||||
|
// this one has been handled above specifically
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await oldParentNode.load(true); // force reload to show up new note
|
||||||
|
|
||||||
|
if (oldParentNode.getChildren().length === 0) {
|
||||||
|
oldParentNode.folder = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldParentNode.renderTitle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -756,5 +756,6 @@ export default {
|
|||||||
loadTree,
|
loadTree,
|
||||||
treeInitialized,
|
treeInitialized,
|
||||||
setExpandedToServer,
|
setExpandedToServer,
|
||||||
getHashValueFromAddress
|
getHashValueFromAddress,
|
||||||
|
getNodesByNoteId
|
||||||
};
|
};
|
@ -86,18 +86,12 @@ async function prepareNode(branch) {
|
|||||||
extraClasses: await getExtraClasses(note),
|
extraClasses: await getExtraClasses(note),
|
||||||
icon: await getIcon(note),
|
icon: await getIcon(note),
|
||||||
refKey: note.noteId,
|
refKey: note.noteId,
|
||||||
expanded: branch.isExpanded || hoistedNoteId === note.noteId
|
expanded: branch.isExpanded || hoistedNoteId === note.noteId,
|
||||||
|
lazy: true
|
||||||
};
|
};
|
||||||
|
|
||||||
if (note.hasChildren() || note.type === 'search') {
|
if (note.hasChildren() || note.type === 'search') {
|
||||||
node.folder = true;
|
node.folder = true;
|
||||||
|
|
||||||
if (node.expanded && note.type !== 'search') {
|
|
||||||
node.children = await prepareRealBranch(note);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
node.lazy = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
@ -151,7 +151,7 @@ class TreeCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Move note from one parent to another. */
|
/* Move note from one parent to another. */
|
||||||
async moveNote(childNoteId, oldParentNoteId, newParentNoteId) {
|
async moveNote(childNoteId, oldParentNoteId, newParentNoteId, beforeNoteId, afterNoteId) {
|
||||||
utils.assertArguments(childNoteId, oldParentNoteId, newParentNoteId);
|
utils.assertArguments(childNoteId, oldParentNoteId, newParentNoteId);
|
||||||
|
|
||||||
if (oldParentNoteId === newParentNoteId) {
|
if (oldParentNoteId === newParentNoteId) {
|
||||||
@ -172,8 +172,18 @@ class TreeCache {
|
|||||||
// add new associations
|
// add new associations
|
||||||
treeCache.parents[childNoteId].push(newParentNoteId);
|
treeCache.parents[childNoteId].push(newParentNoteId);
|
||||||
|
|
||||||
treeCache.children[newParentNoteId] = treeCache.children[newParentNoteId] || []; // this might be first child
|
const children = treeCache.children[newParentNoteId] = treeCache.children[newParentNoteId] || []; // this might be first child
|
||||||
treeCache.children[newParentNoteId].push(childNoteId);
|
|
||||||
|
// we try to put the note into precise order which might be used again by lazy-loaded nodes
|
||||||
|
if (beforeNoteId && children.includes(beforeNoteId)) {
|
||||||
|
children.splice(children.indexOf(beforeNoteId), 0, childNoteId);
|
||||||
|
}
|
||||||
|
else if (afterNoteId && children.includes(afterNoteId)) {
|
||||||
|
children.splice(children.indexOf(afterNoteId) + 1, 0, childNoteId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
children.push(childNoteId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ const keyBindings = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
"ctrl+down": node => {
|
"ctrl+down": node => {
|
||||||
let afterNode = node.getNextSibling();
|
const afterNode = node.getNextSibling();
|
||||||
if (afterNode !== null) {
|
if (afterNode !== null) {
|
||||||
treeChangesService.moveAfterNode([node], afterNode);
|
treeChangesService.moveAfterNode([node], afterNode);
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ const keyBindings = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
"ctrl+right": node => {
|
"ctrl+right": node => {
|
||||||
let toNode = node.getPrevSibling();
|
const toNode = node.getPrevSibling();
|
||||||
|
|
||||||
if (toNode !== null) {
|
if (toNode !== null) {
|
||||||
treeChangesService.moveToNode([node], toNode);
|
treeChangesService.moveToNode([node], toNode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user