mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
cloning is now done without reloading the whole tree
This commit is contained in:
parent
3f656ea76f
commit
ca0d17d93a
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
};
|
@ -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) {
|
||||
|
@ -18,7 +18,7 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
||||
return validationResult;
|
||||
}
|
||||
|
||||
await new Branch({
|
||||
const branch = await new Branch({
|
||||
noteId: noteId,
|
||||
parentNoteId: parentNoteId,
|
||||
prefix: prefix,
|
||||
@ -27,7 +27,7 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
|
||||
|
||||
await sql.execute("UPDATE branches SET isExpanded = 1 WHERE noteId = ?", [parentNoteId]);
|
||||
|
||||
return { success: true };
|
||||
return { success: true, branchId: branch.branchId };
|
||||
}
|
||||
|
||||
async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
|
||||
@ -86,14 +86,14 @@ async function cloneNoteAfter(noteId, afterBranchId) {
|
||||
|
||||
await syncTable.addNoteReorderingSync(afterNote.parentNoteId);
|
||||
|
||||
await new Branch({
|
||||
const branch = await new Branch({
|
||||
noteId: noteId,
|
||||
parentNoteId: afterNote.parentNoteId,
|
||||
notePosition: afterNote.notePosition + 1,
|
||||
isExpanded: 0
|
||||
}).save();
|
||||
|
||||
return { success: true };
|
||||
return { success: true, branchId: branch.branchId };
|
||||
}
|
||||
|
||||
async function isNoteDeleted(noteId) {
|
||||
|
@ -1,5 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
import treeCache from "../public/javascripts/services/tree_cache.js";
|
||||
import treeBuilder from "../public/javascripts/services/tree_builder.js";
|
||||
|
||||
const sql = require('./sql');
|
||||
const repository = require('./repository');
|
||||
const Branch = require('../entities/branch');
|
||||
|
Loading…
x
Reference in New Issue
Block a user