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
fix(autocomplete): step up to the last entry from no highlight
Elian Doran40b60d36708c
diff --git a/apps/client/src/widgets/react/FormAutocomplete.spec.tsx b/apps/client/src/widgets/react/FormAutocomplete.spec.tsxindex f451cd91af..5eef401a44 100644--- a/apps/client/src/widgets/react/FormAutocomplete.spec.tsx+++ b/apps/client/src/widgets/react/FormAutocomplete.spec.tsx@@ -46,6 +46,11 @@ describe("stepping through a list with headings in it", () => {expect(stepOver(items, 1, -1, isHeading)).toBe(4);});+ it("goes up to the last entry from a list with nothing highlighted", () => {+ expect(stepOver(items, -1, -1, isHeading)).toBe(4);+ expect(stepOver([ "a", "b", "c" ], -1, -1)).toBe(2);+ });+it("highlights nothing in a list that is headings alone", () => {expect(stepOver([ "Nearby" ], -1, 1, isHeading)).toBe(-1);});diff --git a/apps/client/src/widgets/react/FormAutocomplete.tsx b/apps/client/src/widgets/react/FormAutocomplete.tsxindex 08bafbdd85..7ecfc9dd87 100644--- a/apps/client/src/widgets/react/FormAutocomplete.tsx+++ b/apps/client/src/widgets/react/FormAutocomplete.tsx@@ -433,7 +433,8 @@ function bestMatchIndex<T>(items: T[], text: string, isHeading: ((item: T) => bo* which row a heading was skipped for.*/export function stepOver<T>(items: T[], from: number, delta: number, isHeading?: (item: T) => boolean) {- let index = from;+ // With nothing highlighted, stepping up starts past the end so that it lands on the last entry.+ let index = from < 0 && delta < 0 ? items.length : from;for (let step = 0; step < items.length; step++) {index = (index + delta + items.length) % items.length;