cloning is now done without reloading the whole tree

This commit is contained in:
zadam
2019-03-18 22:33:19 +01:00
parent 3f656ea76f
commit ca0d17d93a
6 changed files with 52 additions and 27 deletions

View File

@@ -139,22 +139,6 @@ async function moveNodeUpInHierarchy(node) {
node);
}
async function checkFolderStatus(node) {
const children = node.getChildren();
const note = await treeCache.getNote(node.data.noteId);
if (!children || children.length === 0) {
node.folder = false;
node.icon = await treeBuilder.getIcon(note);
node.renderTitle();
}
else if (children && children.length > 0) {
node.folder = true;
node.icon = await treeBuilder.getIcon(note);
node.renderTitle();
}
}
async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
utils.assertArguments(func, node);
@@ -176,8 +160,8 @@ async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
treeService.setCurrentNotePathToHash(node);
await checkFolderStatus(thisOldParentNode);
await checkFolderStatus(thisNewParentNode);
await treeService.checkFolderStatus(thisOldParentNode);
await treeService.checkFolderStatus(thisNewParentNode);
if (!thisNewParentNode.isExpanded()) {
// this expands the note in case it become the folder only after the move
@@ -192,7 +176,7 @@ async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
newParentNode.load(true); // force reload to show up new note
await checkFolderStatus(newParentNode);
await treeService.checkFolderStatus(newParentNode);
}
for (const oldParentNode of treeService.getNodesByNoteId(thisOldParentNode.data.noteId)) {
@@ -203,7 +187,7 @@ async function changeNode(func, node, beforeNoteId = null, afterNoteId = null) {
await oldParentNode.load(true); // force reload to show up new note
await checkFolderStatus(oldParentNode);
await treeService.checkFolderStatus(oldParentNode);
}
}

View File

@@ -1,4 +1,5 @@
import treeService from './tree.js';
import treeCache from './tree_cache.js';
import server from './server.js';
async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
@@ -11,7 +12,9 @@ async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
return;
}
await treeService.reload();
treeCache.addBranchRelationship(resp.branchId, childNoteId, parentNoteId);
await treeService.reloadNote(parentNoteId);
}
// beware that first arg is noteId and second is branchId!
@@ -23,7 +26,11 @@ async function cloneNoteAfter(noteId, afterBranchId) {
return;
}
await treeService.reload();
const afterBranch = await treeCache.getBranch(afterBranchId);
treeCache.addBranchRelationship(resp.branchId, noteId, afterBranch.parentNoteId);
await treeService.reloadNote(afterBranch.parentNoteId);
}
export default {

View File

@@ -708,6 +708,30 @@ function createNoteInto() {
createNote(node, node.data.noteId, 'into', null, node.data.isProtected, true);
}
async function checkFolderStatus(node) {
const children = node.getChildren();
const note = await treeCache.getNote(node.data.noteId);
if (!children || children.length === 0) {
node.folder = false;
node.icon = await treeBuilder.getIcon(note);
node.renderTitle();
}
else if (children && children.length > 0) {
node.folder = true;
node.icon = await treeBuilder.getIcon(note);
node.renderTitle();
}
}
async function reloadNote(noteId) {
for (const node of getNodesByNoteId(noteId)) {
await node.load(true);
await checkFolderStatus(node);
}
}
window.glob.createNoteInto = createNoteInto;
utils.bindShortcut('ctrl+p', createNoteInto);
@@ -757,5 +781,7 @@ export default {
treeInitialized,
setExpandedToServer,
getHashValueFromAddress,
getNodesByNoteId
getNodesByNoteId,
checkFolderStatus,
reloadNote
};

View File

@@ -46,6 +46,8 @@ async function pasteInto(node) {
await treeChangesService.moveToNode(nodes, node);
await node.setExpanded(true);
clipboardIds = [];
clipboardMode = null;
}
@@ -53,6 +55,9 @@ async function pasteInto(node) {
for (const noteId of clipboardIds) {
await cloningService.cloneNoteTo(noteId, node.data.noteId);
}
await node.setExpanded(true);
// copy will keep clipboardIds and clipboardMode so it's possible to paste into multiple places
}
else if (clipboardIds.length === 0) {