mirror of
https://github.com/zadam/trilium.git
synced 2025-10-06 05:25:37 +08:00
feat(views/table): insert row before
This commit is contained in:
parent
5dd5af90c2
commit
8cced607eb
3 changed files with 26 additions and 3 deletions
|
@ -22,7 +22,17 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: F
|
|||
title: "Insert row above",
|
||||
uiIcon: "bx bx-list-plus",
|
||||
handler: () => {
|
||||
|
||||
const target = e.target;
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
const component = $(target).closest(".component").prop("component");
|
||||
component.triggerCommand("addNewRow", {
|
||||
customOpts: {
|
||||
target: "before",
|
||||
targetBranchId: rowData.branchId,
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -110,7 +110,7 @@ function createNote(req: Request) {
|
|||
|
||||
const { target, targetBranchId } = req.query;
|
||||
|
||||
if (target !== "into" && target !== "after") {
|
||||
if (target !== "into" && target !== "after" && target !== "before") {
|
||||
throw new ValidationError("Invalid target type.");
|
||||
}
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ function createNewNote(params: NoteParams): {
|
|||
});
|
||||
}
|
||||
|
||||
function createNewNoteWithTarget(target: "into" | "after", targetBranchId: string | undefined, params: NoteParams) {
|
||||
function createNewNoteWithTarget(target: "into" | "after" | "before", targetBranchId: string | undefined, params: NoteParams) {
|
||||
if (!params.type) {
|
||||
const parentNote = becca.notes[params.parentNoteId];
|
||||
|
||||
|
@ -277,6 +277,19 @@ function createNewNoteWithTarget(target: "into" | "after", targetBranchId: strin
|
|||
|
||||
entityChangesService.putNoteReorderingEntityChange(params.parentNoteId);
|
||||
|
||||
return retObject;
|
||||
} else if (target === "before" && targetBranchId) {
|
||||
const beforeBranch = becca.branches[targetBranchId];
|
||||
|
||||
// not updating utcDateModified to avoid having to sync whole rows
|
||||
sql.execute("UPDATE branches SET notePosition = notePosition - 10 WHERE parentNoteId = ? AND notePosition < ? AND isDeleted = 0", [params.parentNoteId, beforeBranch.notePosition]);
|
||||
|
||||
params.notePosition = beforeBranch.notePosition - 10;
|
||||
|
||||
const retObject = createNewNote(params);
|
||||
|
||||
entityChangesService.putNoteReorderingEntityChange(params.parentNoteId);
|
||||
|
||||
return retObject;
|
||||
} else {
|
||||
throw new Error(`Unknown target '${target}'`);
|
||||
|
|
Loading…
Add table
Reference in a new issue