mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix moving notes up and down using keyboard
This commit is contained in:
parent
b6b6d11ef7
commit
f1338bb643
@ -68,19 +68,31 @@ function moveBranchBeforeNote(req) {
|
|||||||
return [200, validationResult];
|
return [200, validationResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const originalBeforeNotePosition = beforeBranch.notePosition;
|
||||||
|
|
||||||
// we don't change utcDateModified so other changes are prioritized in case of conflict
|
// we don't change utcDateModified so other changes are prioritized in case of conflict
|
||||||
// also we would have to sync all those modified branches otherwise hash checks would fail
|
// also we would have to sync all those modified branches otherwise hash checks would fail
|
||||||
|
|
||||||
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0",
|
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0",
|
||||||
[beforeBranch.parentNoteId, beforeBranch.notePosition]);
|
[beforeBranch.parentNoteId, originalBeforeNotePosition]);
|
||||||
|
|
||||||
|
// also need to update becca positions
|
||||||
|
const parentNote = becca.getNote(beforeBranch.parentNoteId);
|
||||||
|
|
||||||
|
for (const childBranch of parentNote.getChildBranches()) {
|
||||||
|
if (childBranch.notePosition >= originalBeforeNotePosition) {
|
||||||
|
childBranch.notePosition += 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entityChangesService.addNoteReorderingEntityChange(beforeBranch.parentNoteId);
|
entityChangesService.addNoteReorderingEntityChange(beforeBranch.parentNoteId);
|
||||||
|
|
||||||
if (branchToMove.parentNoteId === beforeBranch.parentNoteId) {
|
if (branchToMove.parentNoteId === beforeBranch.parentNoteId) {
|
||||||
branchToMove.notePosition = beforeBranch.notePosition;
|
branchToMove.notePosition = originalBeforeNotePosition;
|
||||||
branchToMove.save();
|
branchToMove.save();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const newBranch = branchToMove.createClone(beforeBranch.parentNoteId, beforeBranch.notePosition);
|
const newBranch = branchToMove.createClone(beforeBranch.parentNoteId, originalBeforeNotePosition);
|
||||||
newBranch.save();
|
newBranch.save();
|
||||||
|
|
||||||
branchToMove.markAsDeleted();
|
branchToMove.markAsDeleted();
|
||||||
@ -101,14 +113,25 @@ function moveBranchAfterNote(req) {
|
|||||||
return [200, validationResult];
|
return [200, validationResult];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const originalAfterNotePosition = afterNote.notePosition;
|
||||||
|
|
||||||
// we don't change utcDateModified so other changes are prioritized in case of conflict
|
// we don't change utcDateModified so other changes are prioritized in case of conflict
|
||||||
// also we would have to sync all those modified branches otherwise hash checks would fail
|
// also we would have to sync all those modified branches otherwise hash checks would fail
|
||||||
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
|
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
|
||||||
[afterNote.parentNoteId, afterNote.notePosition]);
|
[afterNote.parentNoteId, originalAfterNotePosition]);
|
||||||
|
|
||||||
|
// also need to update becca positions
|
||||||
|
const parentNote = becca.getNote(afterNote.parentNoteId);
|
||||||
|
|
||||||
|
for (const childBranch of parentNote.getChildBranches()) {
|
||||||
|
if (childBranch.notePosition > originalAfterNotePosition) {
|
||||||
|
childBranch.notePosition += 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entityChangesService.addNoteReorderingEntityChange(afterNote.parentNoteId);
|
entityChangesService.addNoteReorderingEntityChange(afterNote.parentNoteId);
|
||||||
|
|
||||||
const movedNotePosition = afterNote.notePosition + 10;
|
const movedNotePosition = originalAfterNotePosition + 10;
|
||||||
|
|
||||||
if (branchToMove.parentNoteId === afterNote.parentNoteId) {
|
if (branchToMove.parentNoteId === afterNote.parentNoteId) {
|
||||||
branchToMove.notePosition = movedNotePosition;
|
branchToMove.notePosition = movedNotePosition;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user