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(geomap): stand the first search result ready for Enter
Elian Doran01e157e3ba49
diff --git a/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx b/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsxindex 6b922a1c2f..cd2ee70c81 100644--- a/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx@@ -126,6 +126,14 @@ function labels() {?? entry.textContent);}+/** Presses a key in the field, as the reader reaching for the keyboard rather than the pointer. */+async function press(container: HTMLElement, key: string) {+ await act(async () => {+ field(container).dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true }));+ });+ await settle();+}+/** Picks a row and lets whatever it started settle. */async function pick(index: number) {await act(async () => { entries()[index].click(); });@@ -354,6 +362,37 @@ describe("geo map SearchBox", () => {expect(distances()[1]).toMatch(/^gpx_preview\.unit_km/);});+ it("stands the first row ready, so Enter takes it without arrowing down to it", async () => {+ mockGeocoder([ TOKYO ]);+ const map = fakeMap();+ const container = renderSearchBox(map, mapNotes());++ await type(container, "tokyo");+ expect(entries()[0].className).toContain("active");++ // The map's own note stands first, so Enter goes there rather than to the geocoder.+ await press(container, "Enter");++ expect(map.flyTo).toHaveBeenCalledWith({ center: [ 139.7, 35.6 ], zoom: expect.any(Number) });+ expect(field(container).value).toBe("Tokyo trip");+ });++ it("runs the geocoder on Enter where the map has nothing of its own, and takes the first place on the next", async () => {+ const search = mockGeocoder([ TOKYO ]);+ const map = fakeMap();+ const container = renderSearchBox(map, []);++ // Nothing of the map's own matches, so the row that stands ready is the geocoder's.+ await type(container, "tokyo");+ await press(container, "Enter");+ expect(search).toHaveBeenCalledOnce();++ await press(container, "Enter");++ expect(map.fitBounds).toHaveBeenCalledWith(TOKYO.bounds, expect.anything());+ expect(field(container).value).toBe("Tokyo, Japan");+ });+it("takes the pin off the map once the field is emptied", async () => {mockGeocoder([ TOKYO ]);const container = renderSearchBox(fakeMap(), []);diff --git a/apps/client/src/widgets/collections/geomap/SearchBox.tsx b/apps/client/src/widgets/collections/geomap/SearchBox.tsxindex d05a5335a9..184426a0ac 100644--- a/apps/client/src/widgets/collections/geomap/SearchBox.tsx+++ b/apps/client/src/widgets/collections/geomap/SearchBox.tsx@@ -107,6 +107,10 @@ interface GeocodeRun {* nothing at otherwise leaves the user to work out which patch of ground was meant. The pin stands* until another is taken or the field is emptied.*+ * The rows are the choices themselves rather than help with typing, so the first stands ready and+ * Enter takes it — `autoActivate`, as the attribute pickers use it. From a field holding nothing but+ * a name, that is: Enter, which runs the geocoder, and Enter again, which takes what it found.+ ** `FormAutocomplete` handles the debounce, the stale-response guard, keyboard navigation and a* dropdown portalled out of the map's scrolling container. `keepOpenOnPick` keeps the list up so the* geocoder row can replace itself with results, so closing it after a marker or place is taken is@@ -256,6 +260,7 @@ export default function SearchBox({ notes, isDarkTheme }: SearchBoxProps) {source={source}renderItem={renderEntry}dropdownMinWidth={RESULT_LIST_WIDTH}+ autoActivatekeepOpenOnPickplaceholder={t("geo-map.search-placeholder")}aria-label={t("geo-map.search")}