Skip to content

Build your personal knowledge base with Trilium Notes

fix(autocomplete): keep the child-note row above the results

Elian Doran02cd0ed1a021
diff --git a/apps/client/src/services/note_autocomplete.spec.ts b/apps/client/src/services/note_autocomplete.spec.ts
index 8535fe9735..4da348e20f 100644
--- a/apps/client/src/services/note_autocomplete.spec.ts
+++ b/apps/client/src/services/note_autocomplete.spec.ts
@@ -280,15 +280,15 @@ describe("autocompleteSource (via dataset)", () => {
expect(server.get).not.toHaveBeenCalled();
});
- it("keeps the create-note row above the results and the create-child-note row below them", async () => {
+ it("keeps both creation rows above the results, so neither is scrolled or sliced away", async () => {
server.get = vi.fn(async () => [{ noteTitle: "Existing", notePath: "root/y" }]) as typeof server.get;
const { dataset } = initAndGetSource({ allowCreatingNotes: true, allowJumpToSearchNotes: true });
const rows = await runSource(dataset, "New");
- expect(rows.map((r) => r.action)).toEqual([ "create-note", undefined, "create-child-note", "search-notes" ]);
+ expect(rows.map((r) => r.action)).toEqual([ "create-note", "create-child-note", undefined, "search-notes" ]);
// the inbox is resolved on selection, so the row carries no parent
expect(rows[0].parentNoteId).toBeUndefined();
- expect(rows[1].noteTitle).toBe("Existing");
- expect(rows[2].parentNoteId).toBe("activeNote");
+ expect(rows[1].parentNoteId).toBe("activeNote");
+ expect(rows[2].noteTitle).toBe("Existing");
});
it("uses root as the child-note parent when there is no active note", async () => {
diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts
index 6ef2110fb2..2343718e27 100644
--- a/apps/client/src/services/note_autocomplete.ts
+++ b/apps/client/src/services/note_autocomplete.ts
@@ -130,23 +130,22 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => void
options.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.
+ // Both rows stay above the results: the CKEditor mention feed renders only the first
+ // `mention.dropdownLimit` items, and the jQuery dropdown scrolls past as many as 200.
if (length >= 1 && options.allowCreatingNotes) {
- results = ([
+ results = [
{
action: "create-note",
noteTitle: term,
highlightedNotePathTitle: t("note_autocomplete.create-note", { term })
- }
- ] as Suggestion[]).concat(results, [
+ } as Suggestion,
{
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) {
diff --git a/packages/trilium-e2e/src/support/app.ts b/packages/trilium-e2e/src/support/app.ts
index 80bd485296..74789b4dd3 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 second suggestion is the best candidate; the first is "Create
- // note". Asserting on the suggestion itself (instead of the parent
+ // The best candidate follows the two creation suggestions ("Create note" and
+ // "Create child 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(1);
+ .nth(2);
await expect(suggestionSelector).toContainText(noteTitle);
await suggestionSelector.click();
}