mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 13:50:42 +08:00
fix(note_autocomplete): fix wrong definition of types, and resulting bugs esp. improving row editing
This commit is contained in:
parent
57fc867105
commit
b8367600ad
4 changed files with 35 additions and 40 deletions
|
|
@ -28,7 +28,7 @@ import TouchBarComponent from "./touch_bar.js";
|
|||
import type { CKTextEditor } from "@triliumnext/ckeditor5";
|
||||
import type CodeMirror from "@triliumnext/codemirror";
|
||||
import { StartupChecks } from "./startup_checks.js";
|
||||
import type { CreateNoteOpts } from "../services/note_create.js";
|
||||
import type { CreateNoteOpts, CreateNoteWithUrlOpts } from "../services/note_create.js";
|
||||
import { ColumnComponent } from "tabulator-tables";
|
||||
import { ChooseNoteTypeCallback } from "../widgets/dialogs/note_type_chooser.jsx";
|
||||
import type RootContainer from "../widgets/containers/root_container.js";
|
||||
|
|
@ -357,8 +357,7 @@ export type CommandMappings = {
|
|||
|
||||
// Table view
|
||||
addNewRow: CommandData & {
|
||||
customOpts: CreateNoteOpts;
|
||||
parentNotePath?: string;
|
||||
customOpts?: CreateNoteWithUrlOpts;
|
||||
};
|
||||
addNewTableColumn: CommandData & {
|
||||
columnToEdit?: ColumnComponent;
|
||||
|
|
|
|||
|
|
@ -83,15 +83,18 @@ type CreateNoteBase = {
|
|||
* Serves as a base for "into", "before", and "after" variants,
|
||||
* sharing common URL-related fields.
|
||||
*/
|
||||
export type CreateNoteWithUrlOpts = CreateNoteBase & {
|
||||
target: "into" | "after" | "before";
|
||||
// `Url` may refer to either parentNotePath or parentNoteId.
|
||||
// The vocabulary is inspired by existing function getNoteIdFromUrl.
|
||||
parentNoteUrl: string;
|
||||
|
||||
// Disambiguates the position for cloned notes.
|
||||
targetBranchId?: string;
|
||||
};
|
||||
export type CreateNoteWithUrlOpts =
|
||||
| (CreateNoteBase & {
|
||||
target: "into";
|
||||
parentNoteUrl?: string;
|
||||
// No branch ID needed for "into"
|
||||
})
|
||||
| (CreateNoteBase & {
|
||||
target: "before" | "after";
|
||||
parentNoteUrl?: string;
|
||||
// Required for "before"/"after"
|
||||
targetBranchId: string;
|
||||
});
|
||||
|
||||
export type CreateNoteIntoInboxOpts = CreateNoteBase & {
|
||||
target: "inbox";
|
||||
|
|
@ -134,7 +137,7 @@ async function createNote(
|
|||
case "into":
|
||||
case "before":
|
||||
case "after":
|
||||
return createNoteWithUrl(resolvedOptions.target, resolvedOptions);
|
||||
return createNoteWithUrl(resolvedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +176,6 @@ async function promptForType(
|
|||
* @returns A promise resolving with the created note and its branch.
|
||||
*/
|
||||
async function createNoteWithUrl(
|
||||
target: "into" | "after" | "before",
|
||||
options: CreateNoteWithUrlOpts
|
||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
||||
options = Object.assign(
|
||||
|
|
@ -210,7 +212,12 @@ async function createNoteWithUrl(
|
|||
C-->D;`;
|
||||
}
|
||||
|
||||
const { note, branch } = await server.post<Response>(`notes/${parentNoteId}/children?target=${target}&targetBranchId=${options.targetBranchId || ""}`, {
|
||||
const query =
|
||||
options.target === "into"
|
||||
? `target=${options.target}`
|
||||
: `target=${options.target}&targetBranchId=${options.targetBranchId}`;
|
||||
|
||||
const { note, branch } = await server.post<Response>(`notes/${parentNoteId}/children?${query}`, {
|
||||
title: options.title,
|
||||
content: options.content || "",
|
||||
isProtected: options.isProtected,
|
||||
|
|
@ -269,7 +276,7 @@ async function createNoteIntoInbox(
|
|||
inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable();
|
||||
}
|
||||
|
||||
const result = await createNoteWithUrl("into",
|
||||
const result = await createNoteWithUrl(
|
||||
{
|
||||
...options,
|
||||
target: "into",
|
||||
|
|
|
|||
|
|
@ -181,7 +181,6 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
|||
uiIcon: "bx bx-horizontal-left bx-rotate-90",
|
||||
enabled: !sorters.length,
|
||||
handler: () => parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: parentNoteId,
|
||||
customOpts: {
|
||||
parentNoteUrl: parentNoteId,
|
||||
target: "before",
|
||||
|
|
@ -199,7 +198,6 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
|||
return;
|
||||
}
|
||||
parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: note.noteId,
|
||||
customOpts: {
|
||||
parentNoteUrl: note.noteId,
|
||||
target: "after",
|
||||
|
|
@ -213,7 +211,6 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
|||
uiIcon: "bx bx-horizontal-left bx-rotate-270",
|
||||
enabled: !sorters.length,
|
||||
handler: () => parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: parentNoteId,
|
||||
customOpts: {
|
||||
parentNoteUrl: parentNoteId,
|
||||
target: "after",
|
||||
|
|
|
|||
|
|
@ -9,29 +9,20 @@ import server from "../../../services/server";
|
|||
import branches from "../../../services/branches";
|
||||
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
|
||||
|
||||
export default function useRowTableEditing(api: RefObject<Tabulator>, attributeDetailWidget: AttributeDetailWidget, parentNotePath: string): Partial<EventCallBackMethods> {
|
||||
// Adding new rows
|
||||
export default function useRowTableEditing(api: RefObject<Tabulator>, attributeDetailWidget: AttributeDetailWidget, parentNotePath: string): Partial<EventCallBackMethods> { // Adding new rows
|
||||
useLegacyImperativeHandlers({
|
||||
addNewRowCommand({ customOpts, parentNotePath: customNotePath }: CommandListenerData<"addNewRow">) {
|
||||
const notePath = customNotePath ?? parentNotePath;
|
||||
if (notePath) {
|
||||
const opts: CreateNoteOpts = {
|
||||
activate: false,
|
||||
...customOpts
|
||||
}
|
||||
addNewRowCommand({ customOpts }: CommandListenerData<"addNewRow">) {
|
||||
if (!customOpts) {
|
||||
customOpts = {
|
||||
target: "into",
|
||||
};
|
||||
}
|
||||
|
||||
// Normalize "inbox" targets into standard path-based creation.
|
||||
// When adding a new row, we always have a concrete parent path (`notePath`),
|
||||
// so even if the originating command requested an "inbox" creation,
|
||||
// it should instead behave as "into" under the current note.
|
||||
const normalizedOpts: CreateNoteWithUrlOpts =
|
||||
opts.target === "inbox"
|
||||
? { ...opts, target: "into", parentNoteUrl: notePath }
|
||||
: { ...opts, parentNoteUrl: notePath };
|
||||
|
||||
note_create.createNote(
|
||||
normalizedOpts
|
||||
).then(({ branch }) => {
|
||||
const noteUrl = customOpts.parentNoteUrl ?? parentNotePath;
|
||||
if (noteUrl) {
|
||||
customOpts.parentNoteUrl = noteUrl;
|
||||
customOpts.activate = false;
|
||||
note_create.createNote(customOpts).then(({ branch }) => {
|
||||
if (branch) {
|
||||
setTimeout(() => {
|
||||
if (!api.current) return;
|
||||
|
|
@ -39,6 +30,7 @@ export default function useRowTableEditing(api: RefObject<Tabulator>, attributeD
|
|||
}, 100);
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue