Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(autocomplete): move the child-note row below the results
Elian Doraneb5a038a16ea
diff --git a/apps/client/src/services/note_autocomplete.spec.ts b/apps/client/src/services/note_autocomplete.spec.tsindex 80cf754599..8535fe9735 100644--- a/apps/client/src/services/note_autocomplete.spec.ts+++ b/apps/client/src/services/note_autocomplete.spec.ts@@ -280,16 +280,15 @@ describe("autocompleteSource (via dataset)", () => {expect(server.get).not.toHaveBeenCalled();});- it("prepends create-note and create-child-note suggestions when allowCreatingNotes and term is non-empty", async () => {+ it("keeps the create-note row above the results and the create-child-note row below them", async () => {server.get = vi.fn(async () => [{ noteTitle: "Existing", notePath: "root/y" }]) as typeof server.get;- const { dataset } = initAndGetSource({ allowCreatingNotes: true });+ const { dataset } = initAndGetSource({ allowCreatingNotes: true, allowJumpToSearchNotes: true });const rows = await runSource(dataset, "New");- expect(rows[0].action).toBe("create-note");+ expect(rows.map((r) => r.action)).toEqual([ "create-note", undefined, "create-child-note", "search-notes" ]);// the inbox is resolved on selection, so the row carries no parentexpect(rows[0].parentNoteId).toBeUndefined();- expect(rows[1].action).toBe("create-child-note");- expect(rows[1].parentNoteId).toBe("activeNote");- expect(rows[2].noteTitle).toBe("Existing");+ expect(rows[1].noteTitle).toBe("Existing");+ expect(rows[2].parentNoteId).toBe("activeNote");});it("uses root as the child-note parent when there is no active note", async () => {@@ -297,7 +296,8 @@ describe("autocompleteSource (via dataset)", () => {server.get = vi.fn(async () => []) as typeof server.get;const { dataset } = initAndGetSource({ allowCreatingNotes: true });const rows = await runSource(dataset, "New");- expect(rows[1].parentNoteId).toBe("root");+ const childRow = rows.find((r) => r.action === "create-child-note");+ expect(childRow?.parentNoteId).toBe("root");});it("appends a search-notes suggestion when allowJumpToSearchNotes", async () => {@@ -367,7 +367,7 @@ describe("autocompleteSource (via dataset)", () => {expect(dataset.templates.suggestion({ action: "create-note", highlightedNotePathTitle: "C" })).toContain("bx bx-plus");expect(dataset.templates.suggestion({ action: "create-child-note", highlightedNotePathTitle: "C" }))- .toContain("bx bx-plus");+ .toContain("bx bx-subdirectory-right");expect(dataset.templates.suggestion({ action: "external-link", highlightedNotePathTitle: "E" })).toContain("bx bx-link-external");});diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.tsindex 609d649180..6ef2110fb2 100644--- a/apps/client/src/services/note_autocomplete.ts+++ b/apps/client/src/services/note_autocomplete.ts@@ -130,20 +130,23 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => voidoptions.fastSearch = true;+ // The inbox row holds the single slot above the results, so their positions are the same as+ // before it existed; the child-note row sits with the other secondary actions at the bottom.if (length >= 1 && options.allowCreatingNotes) {- results = [+ results = ([{action: "create-note",noteTitle: term,highlightedNotePathTitle: t("note_autocomplete.create-note", { term })- } as Suggestion,+ }+ ] as Suggestion[]).concat(results, [{action: "create-child-note",noteTitle: term,parentNoteId: activeNoteId || "root",highlightedNotePathTitle: t("note_autocomplete.create-child-note", { term })} as Suggestion- ].concat(results);+ ]);}if (length >= 1 && options.allowJumpToSearchNotes) {@@ -362,8 +365,10 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {let iconClass = suggestion.icon ?? "bx bx-note";if (suggestion.action === "search-notes") {iconClass = "bx bx-search";- } else if (suggestion.action === "create-note" || suggestion.action === "create-child-note") {+ } else if (suggestion.action === "create-note") {iconClass = "bx bx-plus";+ } else if (suggestion.action === "create-child-note") {+ iconClass = "bx bx-subdirectory-right";} else if (suggestion.action === "external-link") {iconClass = "bx bx-link-external";}diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsxindex 3ac9bcb2ab..0c5423e2d4 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx@@ -39,8 +39,10 @@ const mentionFeeds: MentionFeed[] = [const iconElement = document.createElement("span");let iconClass = item.icon ?? "bx bx-note";- if (item.action === "create-note" || item.action === "create-child-note") {+ if (item.action === "create-note") {iconClass = "bx bx-plus";+ } else if (item.action === "create-child-note") {+ iconClass = "bx bx-subdirectory-right";}iconElement.className = iconClass;diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.tsindex be4a08f778..b5fcbd6293 100644--- a/apps/client/src/widgets/type_widgets/text/config.ts+++ b/apps/client/src/widgets/type_widgets/text/config.ts@@ -305,8 +305,10 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConficonst iconElement = document.createElement("span");// Choose appropriate icon based on actionlet iconClass = suggestion.icon ?? "bx bx-note";- if (suggestion.action === "create-note" || suggestion.action === "create-child-note") {+ if (suggestion.action === "create-note") {iconClass = "bx bx-plus";+ } else if (suggestion.action === "create-child-note") {+ iconClass = "bx bx-subdirectory-right";}iconElement.className = iconClass;diff --git a/packages/trilium-e2e/src/support/app.ts b/packages/trilium-e2e/src/support/app.tsindex 74789b4dd3..80bd485296 100644--- a/packages/trilium-e2e/src/support/app.ts+++ b/packages/trilium-e2e/src/support/app.ts@@ -107,13 +107,13 @@ export default class App {await autocomplete.clear();await autocomplete.pressSequentially(noteTitle);- // The best candidate follows the two creation suggestions ("Create note" and- // "Create child note"). Asserting on the suggestion itself (instead of the parent+ // The second suggestion is the best candidate; the first is "Create+ // note". Asserting on the suggestion itself (instead of the parent// `.note-detail-empty-results`, which also contains the recent-notes// list) ensures the dropdown actually opened.const suggestionSelector = this.currentNoteSplit.locator(".note-detail-empty-results .aa-suggestion")- .nth(2);+ .nth(1);await expect(suggestionSelector).toContainText(noteTitle);await suggestionSelector.click();}