mirror of
https://github.com/zadam/trilium.git
synced 2025-03-05 03:25:59 +08:00
fixed "duplicate subtree" creating extra entities in case subtrees contains multiple clones
This commit is contained in:
parent
08cba1e1ce
commit
50bcf45113
1 changed files with 22 additions and 8 deletions
|
@ -796,8 +796,28 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
|
||||||
throw new Error(`Cannot duplicate note=${origNote.noteId} because it is protected and protected session is not available. Enter protected session and try again.`);
|
throw new Error(`Cannot duplicate note=${origNote.noteId} because it is protected and protected session is not available. Enter protected session and try again.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newNoteId = noteIdMapping[origNote.noteId];
|
||||||
|
|
||||||
|
const newBranch = new Branch({
|
||||||
|
noteId: newNoteId,
|
||||||
|
parentNoteId: newParentNoteId,
|
||||||
|
// here increasing just by 1 to make sure it's directly after original
|
||||||
|
notePosition: origBranch ? origBranch.notePosition + 1 : null
|
||||||
|
}).save();
|
||||||
|
|
||||||
|
const existingNote = repository.getNote(newNoteId);
|
||||||
|
|
||||||
|
if (existingNote) {
|
||||||
|
// note has multiple clones and was already created from another placement in the tree
|
||||||
|
// so a branch is all we need for this clone
|
||||||
|
return {
|
||||||
|
note: existingNote,
|
||||||
|
branch: newBranch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const newNote = new Note(origNote);
|
const newNote = new Note(origNote);
|
||||||
newNote.noteId = noteIdMapping[origNote.noteId];
|
newNote.noteId = newNoteId;
|
||||||
newNote.dateCreated = dateUtils.localNowDateTime();
|
newNote.dateCreated = dateUtils.localNowDateTime();
|
||||||
newNote.utcDateCreated = dateUtils.utcNowDateTime();
|
newNote.utcDateCreated = dateUtils.utcNowDateTime();
|
||||||
newNote.save();
|
newNote.save();
|
||||||
|
@ -811,13 +831,6 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
|
||||||
|
|
||||||
newNote.setContent(content);
|
newNote.setContent(content);
|
||||||
|
|
||||||
const newBranch = new Branch({
|
|
||||||
noteId: newNote.noteId,
|
|
||||||
parentNoteId: newParentNoteId,
|
|
||||||
// here increasing just by 1 to make sure it's directly after original
|
|
||||||
notePosition: origBranch ? origBranch.notePosition + 1 : null
|
|
||||||
}).save();
|
|
||||||
|
|
||||||
for (const attribute of origNote.getOwnedAttributes()) {
|
for (const attribute of origNote.getOwnedAttributes()) {
|
||||||
const attr = new Attribute(attribute);
|
const attr = new Attribute(attribute);
|
||||||
attr.attributeId = undefined; // force creation of new attribute
|
attr.attributeId = undefined; // force creation of new attribute
|
||||||
|
@ -849,6 +862,7 @@ function getNoteIdMapping(origNote) {
|
||||||
for (const origNoteId of origNote.getDescendantNoteIds()) {
|
for (const origNoteId of origNote.getDescendantNoteIds()) {
|
||||||
noteIdMapping[origNoteId] = utils.newEntityId();
|
noteIdMapping[origNoteId] = utils.newEntityId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return noteIdMapping;
|
return noteIdMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue