Skip to content

Build your personal knowledge base with Trilium Notes

fix(geomap): let Escape close the marker's pane from inside it

Elian Doran89fc72566ee9
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
index 9d77c16969..d614bd3960 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
@@ -157,6 +157,27 @@ describe("DetailPane", () => {
expect(pane()).toBeNull();
});
+
+ /**
+ * The panel stops the key presses made inside it from reaching what is underneath, which is a
+ * map with shortcuts of its own — and which would stop them reaching the pane's own listener
+ * too, were that one not heard on the way down.
+ */
+ it("closes on Escape pressed with the focus inside the pane", async () => {
+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
+ const map = fakeMap();
+ await mount([ note ], map);
+
+ map.setUnderPointer([ markerFeature(note) ]);
+ await act(async () => map.click());
+ expect(pane()).toBeTruthy();
+
+ await act(async () => {
+ pane()?.dispatchEvent(new KeyboardEvent("keydown", { bubbles: true, key: "Escape" }));
+ });
+ expect(pane()).toBeNull();
+ });
+
it("leaves the click alone while the map is armed to place something", async () => {
const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
const map = fakeMap();
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index fc2925e69a..75886b3f63 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -77,8 +77,13 @@ export default function DetailPane({ notes, placing }: {
setSelectedNoteId(null);
}
};
- window.addEventListener("keydown", onKeyDown);
- return () => window.removeEventListener("keydown", onKeyDown);
+ // Heard on the way down rather than on the way up: the panel stops the key presses made
+ // inside it from reaching what is underneath (see OverlayPanel), which is right — what is
+ // underneath is a map with shortcuts of its own — but it also stops them reaching this. On
+ // the way down nothing has had the chance to stop them yet, so Escape closes the pane from
+ // within it as readily as from the map.
+ window.addEventListener("keydown", onKeyDown, true);
+ return () => window.removeEventListener("keydown", onKeyDown, true);
}, [ selectedNoteId ]);
if (!note) {