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): drop the title prompt and open a created note straight into its pane
Elian Doran503bb4dcc6f5
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 7eb7f67451..03d1036972 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2752,6 +2752,8 @@"exit-fullscreen": "Exit fullscreen","close-details": "Close","open-note": "Open note",+ "more-ways-to-open": "More ways to open",+ "marker-color": "Marker color","copy-coordinates": "Copy coordinates"},"geo-map-context": {diff --git a/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx b/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsxindex b428071c3a..a4a71a919d 100644--- a/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx@@ -65,14 +65,13 @@ function fakeMap(markerUnderPointer?: FNote, trackUnderPointer?: FNote) {}/** Opens the menu over the given map and hands back the items it was shown with. */-async function openMenu(map: ReturnType<typeof fakeMap>, { isReadOnly = false, onRelocate = vi.fn() } = {}) {- const note = buildNote({ title: "The map itself" });+async function openMenu(map: ReturnType<typeof fakeMap>, { isReadOnly = false, onRelocate = vi.fn(), onCreateNote = vi.fn() } = {}) {// Settled before the map is clicked: the listener the menu opens from is bound in an effect, and// effects do not run within the render itself.await act(async () => {renderInto(<ParentMap.Provider value={map as never}>- <ContextMenus note={note} isReadOnly={isReadOnly} onRelocate={onRelocate} />+ <ContextMenus isReadOnly={isReadOnly} onRelocate={onRelocate} onCreateNote={onCreateNote} /></ParentMap.Provider>);});@@ -81,7 +80,7 @@ async function openMenu(map: ReturnType<typeof fakeMap>, { isReadOnly = false, oact(() => { map.rightClick(); });const items: MenuItem<string>[] = show.mock.calls[0]?.[0]?.items ?? [];- return { items, onRelocate };+ return { items, onRelocate, onCreateNote };}/** The item offering to move a marker, where one was offered. */@@ -117,6 +116,21 @@ describe("ContextMenus", () => {expect(items).toContainEqual(expect.objectContaining({ title: "geo-map-context.add-note" }));});+ /**+ * Adding a note goes through the map view rather than being done here: the click has named the+ * place already, so the map creates the note there and opens the pane on it — the same road a+ * note created by the armed click takes (see `createNoteAt` in index.tsx).+ */+ it("hands the map the place a note was asked for", async () => {+ const { items, onCreateNote } = await openMenu(fakeMap());++ const add = items.find((item): item is MenuCommandItem<string> =>+ "title" in item && item.title === "geo-map-context.add-note");+ add?.handler?.(add, undefined as never);++ expect(onCreateNote).toHaveBeenCalledWith(expect.objectContaining({ latlng: { lat: 1, lng: 2 } }));+ });+it("opens the note of a GPX track that was clicked, not the map's own menu", async () => {const track = buildNote({ title: "A Sunday ride" });const { items } = await openMenu(fakeMap(undefined, track));diff --git a/apps/client/src/widgets/collections/geomap/ContextMenus.ts b/apps/client/src/widgets/collections/geomap/ContextMenus.tsindex b342c1d48e..fc0dea2c30 100644--- a/apps/client/src/widgets/collections/geomap/ContextMenus.ts+++ b/apps/client/src/widgets/collections/geomap/ContextMenus.ts@@ -2,20 +2,17 @@ import { MapMouseEvent } from "maplibre-gl";import { useCallback, useContext, useEffect } from "preact/hooks";import appContext, { type CommandMappings } from "../../../components/app_context.js";-import FNote from "../../../entities/fnote.js";import contextMenu, { type MenuItem } from "../../../menus/context_menu.js";import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker.jsx";import linkContextMenu from "../../../menus/link_context_menu.js";import { copyTextWithToast } from "../../../services/clipboard_ext.js";import { t } from "../../../services/i18n.js";import link from "../../../services/link.js";-import { createNewNote } from "./api.js";import { trackHitLayers } from "./GpxTrack.js";import { type GeoMouseEvent, ParentMap, toGeoMouseEvent } from "./map.js";import { formatLocation, MARKER_LAYER } from "./Markers.js";interface ContextMenusProps {- note: FNote;isReadOnly: boolean;/*** Arms this map for the marker of the given note to be put somewhere else, the next click on the@@ -24,9 +21,15 @@ interface ContextMenusProps {* (see the same reasoning around note placement in `index.tsx`).*/onRelocate: (noteId: string) => void;+ /**+ * Creates a note where the click landed. Handed down rather than done here because creating is+ * only half of what the map does with a new note — it opens the pane on it too, and the pane's+ * selection lives with the map (see `createNoteAt` in `index.tsx`).+ */+ onCreateNote: (e: GeoMouseEvent) => void;}-export default function ContextMenus({ note, isReadOnly, onRelocate }: ContextMenusProps) {+export default function ContextMenus({ isReadOnly, onRelocate, onCreateNote }: ContextMenusProps) {const map = useContext(ParentMap);const onContextMenu = useCallback((e: GeoMouseEvent) => {@@ -43,9 +46,9 @@ export default function ContextMenus({ note, isReadOnly, onRelocate }: ContextMeopenContextMenu(features[0].properties.id, e, !isReadOnly, onRelocate);} else {// Empty area context menu.- openMapContextMenu(note, e, !isReadOnly);+ openMapContextMenu(e, !isReadOnly, onCreateNote);}- }, [ map, note, isReadOnly, onRelocate ]);+ }, [ map, isReadOnly, onRelocate, onCreateNote ]);useEffect(() => {if (!onContextMenu || !map) return;@@ -101,7 +104,7 @@ export function openContextMenu(noteId: string, e: GeoMouseEvent, isEditable: bo});}-export function openMapContextMenu(note: FNote, e: GeoMouseEvent, isEditable: boolean) {+export function openMapContextMenu(e: GeoMouseEvent, isEditable: boolean, onCreateNote: (e: GeoMouseEvent) => void) {let items: MenuItem<keyof CommandMappings>[] = [...buildGeoLocationItem(e)];@@ -112,7 +115,9 @@ export function openMapContextMenu(note: FNote, e: GeoMouseEvent, isEditable: bo{ kind: "separator" },{title: t("geo-map-context.add-note"),- handler: () => createNewNote(note, e),+ // The click named the place already, so this skips the armed-click step entirely:+ // the note is created here and the pane opened on it, like any other creation.+ handler: () => onCreateNote(e),uiIcon: "bx bx-plus"}];diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.css b/apps/client/src/widgets/collections/geomap/DetailPane.cssindex 9e7279daa2..7feaa27333 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.css+++ b/apps/client/src/widgets/collections/geomap/DetailPane.css@@ -175,11 +175,35 @@align-items: center;gap: 4px;- /* The two that write rather than read stand apart from the four being reached for repeatedly, so+ /*+ * The two halves of the split read as the one control they are: the way in, and the arrow+ * offering the other ways.+ *+ * A button group joins its own children — squares the corners where they meet and pulls the+ * second onto the first's border — but the dropdown brings a wrapper of its own, so neither+ * rule reaches the arrow and it stands off as a rounded box of its own. Joined by hand here.+ */+ .geo-detail-pane-open {+ > .geo-detail-pane-open-note {+ border-start-end-radius: 0;+ border-end-end-radius: 0;+ }++ > .dropdown {+ margin-inline-start: -1px;++ > .btn {+ border-start-start-radius: 0;+ border-end-start-radius: 0;+ }+ }+ }++ /* Those that write rather than read stand apart from the ones being reached for repeatedly, sothe pointer cannot land on one of them by being a moment early. The gap falls before the first- of the pair, which is the move: both are drawn together or not at all, a read-only map having- neither. */- .geo-detail-pane-move {+ of them, which is the colour: they are drawn together or not at all, a read-only map having+ none of them. */+ .geo-detail-pane-color {margin-inline-start: auto;}}diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsxindex 4d0aa92919..45b45862b2 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx@@ -1,5 +1,6 @@import $ from "jquery";import { render } from "preact";+import { useState } from "preact/hooks";import { act } from "preact/test-utils";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";@@ -7,13 +8,14 @@ import appContext from "../../../components/app_context";import Component from "../../../components/component";import type FNote from "../../../entities/fnote";import attributes from "../../../services/attributes";+import linkContextMenu from "../../../menus/link_context_menu";import froca from "../../../services/froca";import link from "../../../services/link";import server from "../../../services/server";import { buildNote } from "../../../test/easy-froca";import { useLegacyImperativeHandlers, useNoteContext, useTriliumEvent } from "../../react/hooks";import { ParentComponent } from "../../react/react_utils";-import DetailPane from "./DetailPane";+import DetailPane, { OTHER_WAYS_TO_OPEN, PaneSelection } from "./DetailPane";import { ParentMap } from "./map";import { MARKER_LAYER } from "./Markers";@@ -139,14 +141,33 @@ describe("DetailPane", () => {/** Stands in for the map's own component, which is what the pane hangs under. */let mapComponent: Component | undefined;+ /**+ * Stands in for the map view, which is what owns the selection now (see PaneSelection): the pane+ * asks for changes through `onSelect` and is handed the result back, exactly as GeoView does it.+ * `initialSelection` is the map view opening the pane by hand — on a note it has just created.+ */+ function Harness({ notes, placing, isReadOnly, initialSelection }: {+ notes: FNote[]; placing: boolean; isReadOnly: boolean; initialSelection?: PaneSelection;+ }) {+ const [ selection, setSelection ] = useState<PaneSelection | null>(initialSelection ?? null);+ return <DetailPane+ notes={notes}+ placing={placing}+ isReadOnly={isReadOnly}+ selection={selection}+ onSelect={setSelection}+ onRelocate={onRelocate}+ />;+ }+/** Renders into the same container, so calling it again is a re-render with fresh props. */- function mount(notes: FNote[], map: ReturnType<typeof fakeMap>, placing = false, isReadOnly = false) {+ function mount(notes: FNote[], map: ReturnType<typeof fakeMap>, placing = false, isReadOnly = false, initialSelection?: PaneSelection) {mapComponent ??= new Component();return act(async () => {render(<ParentComponent.Provider value={mapComponent as Component}><ParentMap.Provider value={map as never}>- <DetailPane notes={notes} placing={placing} isReadOnly={isReadOnly} onRelocate={onRelocate} />+ <Harness notes={notes} placing={placing} isReadOnly={isReadOnly} initialSelection={initialSelection} /></ParentMap.Provider></ParentComponent.Provider>,container as HTMLElement@@ -275,6 +296,42 @@ describe("DetailPane", () => {expect(map.eased).toEqual([ { center: [ 2, 1 ], offset: [ 0, 0 ] } ]);});+ /**+ * The way in for a note the map has just created (see `createNoteAt` in index.tsx): no click —+ * the map hands the pane the selection, marked as new, and the pane opens ready for the one+ * thing the note still lacks, a name.+ */+ it("opens on a note it is handed, with the stock name selected to be typed over", async () => {+ buildNote({ id: "root", title: "root", children: [ { id: "fresh", title: "new note", "#geolocation": "1,2" } ] });+ const note = froca.notes["fresh"];+ const map = fakeMap();++ // What the title widget asks before taking the focus; nothing in this DOM has a layout to+ // answer it with, so the answer a drawn pane would give is supplied by hand.+ (HTMLElement.prototype as { checkVisibility?: () => boolean }).checkVisibility = () => true;+ // The selecting itself is asserted as a call: happy-dom keeps no faithful selection range —+ // the controlled value write walks the caret to the end regardless of what select() did.+ const select = vi.spyOn(HTMLInputElement.prototype, "select");++ try {+ await mount([ note ], map, false, false, { noteId: note.noteId, isNew: true });+ await settle();++ // Open and held clear of the pane, exactly as if the marker had been clicked.+ expect(pane()).toBeTruthy();+ expect(map.eased).toEqual([ { center: [ 2, 1 ], offset: [ -200, 0 ] } ]);++ // The caret is in the title with the whole of the stock name selected: naming the+ // place is typing over it, not clearing a field first.+ const title = pane()?.querySelector<HTMLInputElement>(".title-row input");+ expect(title?.value).toBe("new note");+ expect(document.activeElement).toBe(title);+ expect(select.mock.instances).toContain(title);+ } finally {+ select.mockRestore();+ }+ });+it("clears on a click that misses every marker, and on Escape", async () => {const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });const map = fakeMap();@@ -373,34 +430,46 @@ describe("DetailPane", () => {// one is searched from.const notePath = "root/places/somewhere";const bestNotePath = vi.spyOn(note, "getBestNotePathString").mockReturnValue(notePath);- const openContextWithNote = vi.spyOn(appContext.tabManager, "openContextWithNote").mockResolvedValue(undefined as never);- const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockResolvedValue(undefined);const goToLinkExt = vi.spyOn(link, "goToLinkExt").mockReturnValue(true);try {await openPaneFor(note, map);- press("bx-log-in");+ // The half of the split that is a button in its own right, the rest being behind its+ // arrow.+ container?.querySelector<HTMLButtonElement>(".geo-detail-pane-open-note")?.click();expect(openInCurrentNoteContext).toHaveBeenCalledWith(expect.anything(), notePath);- press("bx-link-external");- expect(openContextWithNote).toHaveBeenCalledWith(notePath, { hoistedNoteId: undefined });-- press("bx-window-open");- expect(triggerCommand).toHaveBeenCalledWith("openInWindow", { notePath, hoistedNoteId: undefined });-// Latitude first, as a geo URI is written and as the map's own menu hands one over —// the note stores it that way round, and the features the map draws do not.press("bx-map-alt");expect(goToLinkExt).toHaveBeenCalledWith(null, "geo:1,2");} finally {bestNotePath.mockRestore();- openContextWithNote.mockRestore();- triggerCommand.mockRestore();goToLinkExt.mockRestore();openInCurrentNoteContext.mockClear();}});++ /**+ * The rest live behind the split's arrow, and are the same ways a link offers anywhere in+ * the app — which is how a split view, the one worth having beside a map, comes to be+ * offered at all: the row of buttons this replaced never had one.+ *+ * The pane names them itself, the shared menu wanting an event it cannot be handed before+ * anything is pressed, so what is pinned here is that the two lists stay the same list. Add+ * a fifth way to open a link and this fails until the pane offers it too.+ */+ it("offers behind the split exactly the ways a link is opened anywhere else", async () => {+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });+ const map = fakeMap();+ await openPaneFor(note, map);++ expect(container?.querySelector(".dropdown-toggle-split")).toBeTruthy();+ expect(OTHER_WAYS_TO_OPEN.map((way) => way.command)).toEqual(+ linkContextMenu.getItems(new MouseEvent("click"))+ .map((item) => ("command" in item ? item.command : undefined)));+ });});describe("the note itself", () => {@@ -623,7 +692,7 @@ describe("DetailPane", () => {// The ways of reading the note stay; the one that writes it does not.expect(pane()).toBeTruthy();- expect(container?.querySelector(".geo-detail-pane-actions button.bx-log-in")).toBeTruthy();+ expect(container?.querySelector(".geo-detail-pane-open-note")).toBeTruthy();expect(removeButton()).toBeNull();});});diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsxindex 31bb377d16..7fe3df5c8d 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx@@ -8,6 +8,8 @@ import appContext from "../../../components/app_context";import Component from "../../../components/component";import NoteContext, { openInCurrentNoteContext } from "../../../components/note_context";import FNote from "../../../entities/fnote";+import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker";+import linkContextMenu from "../../../menus/link_context_menu";import { copyTextWithToast } from "../../../services/clipboard_ext";import { t } from "../../../services/i18n";import link from "../../../services/link";@@ -15,13 +17,30 @@ import TitleRow from "../../layout/TitleRow";import NoteDetail from "../../NoteDetail";import PromotedAttributes from "../../PromotedAttributes";import ActionButton from "../../react/ActionButton";-import { useLegacyComponentElement, useNoteColorClass, useNoteLabel, useStaticTooltip } from "../../react/hooks";+import Button, { ButtonGroup } from "../../react/Button";+import Dropdown from "../../react/Dropdown";+import { FormListItem } from "../../react/FormList";+import { useLegacyComponentElement, useNoteColorClass, useNoteContext, useNoteLabel, useStaticTooltip } from "../../react/hooks";import OverlayPanel, { OverlayPanelBody } from "../../react/OverlayPanel";import { NoteContextContext, ParentComponent } from "../../react/react_utils";import { moveMarker } from "./api";import { ParentMap } from "./map";import { formatLocation, LOCATION_ATTRIBUTE, MARKER_LAYER, parseLocation } from "./Markers";+/**+ * Which marker the pane stands for, and why it came to be selected.+ *+ * Owned by the map view rather than by the pane, because a click on a marker is no longer the only+ * way in: a note just created on the map is opened into the pane by the code that created it (see+ * index.tsx), and state the pane kept to itself could not be set from there.+ */+export interface PaneSelection {+ noteId: string;+ /** Created a moment ago, so the pane opens with the stock title selected, ready to be typed+ * over — the note has no name yet worth protecting from a keystroke. */+ isNew?: boolean;+}+/*** The pane standing against the trailing edge of the map for as long as a marker is selected.*@@ -29,18 +48,21 @@ import { formatLocation, LOCATION_ATTRIBUTE, MARKER_LAYER, parseLocation } from* pane outside it would leave the screen. It reads as a dock because the map keeps out of its way* (see {@link paneOffset}).*/-export default function DetailPane({ notes, placing, isReadOnly, onRelocate }: {+export default function DetailPane({ notes, placing, isReadOnly, selection, onSelect, onRelocate }: {notes: FNote[];/** A marker is being placed, which is what the next click on the map is for. */placing: boolean;/** The map may not be edited, which leaves the pane the ways of opening a note and no more. */isReadOnly: boolean;+ /** The marker the pane stands for, or `null` for a pane that is not up. See {@link PaneSelection}. */+ selection: PaneSelection | null;+ /** How the pane asks for its selection to change — a marker clicked, or nothing at all. */+ onSelect: (selection: PaneSelection | null) => void;/** Arms this map for the selected marker to be put somewhere else, the next click being where. */onRelocate: (noteId: string) => void;}) {const map = useContext(ParentMap);- const [ selectedNoteId, setSelectedNoteId ] = useState<string | null>(null);- const note = notes.find((note) => note.noteId === selectedNoteId);+ const note = notes.find((note) => note.noteId === selection?.noteId);const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);const { noteContext, paneComponent } = usePaneNoteContext(note);@@ -58,8 +80,8 @@ export default function DetailPane({ notes, placing, isReadOnly, onRelocate }: {*/const closePane = useCallback(() => {void paneComponent.handleEventInChildren("beforeNoteContextRemove", { ntxIds: [ PANE_NTX_ID ] });- setSelectedNoteId(null);- }, [ paneComponent ]);+ onSelect(null);+ }, [ paneComponent, onSelect ]);/*** Arms the map for this marker to be put somewhere else, and stands the pane down while it waits.@@ -78,10 +100,10 @@ export default function DetailPane({ notes, placing, isReadOnly, onRelocate }: {// A note no longer on the map takes the pane with it. Its location may merely have been cleared// — which is all "remove from map" does — so the note being gone is not the only case.useEffect(() => {- if (selectedNoteId && (!note || !parseLocation(location))) {+ if (selection && (!note || !parseLocation(location))) {void closePane();}- }, [ selectedNoteId, note, location, closePane ]);+ }, [ selection, note, location, closePane ]);// A marker selects, anywhere else clears. Read off the rendered layer rather than bound to it// (`map.on("click", MARKER_LAYER, ...)`) so one handler answers both, with no ordering to rely on.@@ -95,21 +117,30 @@ export default function DetailPane({ notes, placing, isReadOnly, onRelocate }: {return;}- setSelectedNoteId(String(feature.properties.id));- map.easeTo({- center: feature.geometry.coordinates as [ number, number ],- offset: paneOffset(map)- });+ onSelect({ noteId: String(feature.properties.id) });};map.on("click", onClick);return () => { map.off("click", onClick); };- }, [ map, placing, closePane ]);+ }, [ map, placing, closePane, onSelect ]);++ // The marker is brought to the middle of what the pane leaves uncovered. Off the selection+ // rather than in the click handler, so a marker the map opened by hand — the note it has just+ // created — is held clear of the pane the same way as one that was clicked; and off the+ // location too, so a marker that has just been put somewhere else is followed there.+ useEffect(() => {+ if (!map || !note) return;++ const coordinates = parseLocation(location);+ if (!coordinates) return;++ map.easeTo({ center: coordinates, offset: paneOffset(map) });+ }, [ map, note?.noteId, location ]);// Bound only while something is selected, so the map's other Escape — giving up on placing a// marker (see index.tsx) — stands alone when nothing is.useEffect(() => {- if (!selectedNoteId) return;+ if (!selection) return;const onKeyDown = (e: KeyboardEvent) => {if (e.key === "Escape") {@@ -120,7 +151,7 @@ export default function DetailPane({ notes, placing, isReadOnly, onRelocate }: {// underneath (see OverlayPanel), which would stop them reaching this listener too.window.addEventListener("keydown", onKeyDown, true);return () => window.removeEventListener("keydown", onKeyDown, true);- }, [ selectedNoteId, closePane ]);+ }, [ selection?.noteId, closePane ]);if (!note) {return null;@@ -132,11 +163,39 @@ export default function DetailPane({ notes, placing, isReadOnly, onRelocate }: {<ParentComponent.Provider value={paneComponent}><NoteContextContext.Provider value={noteContext}><MarkerDetails note={note} isReadOnly={isReadOnly} onClose={closePane} onRelocate={relocate} />+ {selection?.isNew && <SelectTitleOnFirstOpen />}</NoteContextContext.Provider></ParentComponent.Provider>);}+/**+ * Puts the caret in the title with the whole of the stock name selected — how the pane opens on a+ * note the map has just created, whose name is the one thing it still lacks (see PaneSelection).+ *+ * A component rather than a call after `setNote`, because only rendering says when there is an+ * input to focus: the title widget grows one as the switch's announcement works through it, over+ * more than one render, and a dispatch fired after any fixed delay is a bet on how many. This+ * hears the announcement the same way the title widget does, so by the time its effect runs, the+ * commit that mounted the input is done. The widget matches the event on the pane's ntxId, as it+ * matches the one note_create raises for a note created anywhere else.+ */+function SelectTitleOnFirstOpen() {+ const { note } = useNoteContext();+ const parentComponent = useContext(ParentComponent);+ // Once per opening: the note being edited re-announces itself (a rename saving, say), and the+ // caret must not jump back to the title mid-thought.+ const done = useRef(false);++ useEffect(() => {+ if (!note || done.current || !parentComponent) return;+ done.current = true;+ void parentComponent.handleEventInChildren("focusAndSelectTitle", { isNewNote: true, ntxId: PANE_NTX_ID });+ }, [ note?.noteId, parentComponent ]);++ return null;+}+/** Must agree with `--geo-detail-pane-width` in DetailPane.css. */const PANE_WIDTH = 380;@@ -274,10 +333,16 @@ function usePaneNoteContext(note: FNote | undefined) {}/**- * The ways of opening the note, named as the link menu names them.+ * What can be done with the marker: the ways of opening its note, then the ways of changing it.*- * The quick editor is deliberately absent: it is what a click on a marker used to raise, and the- * pane took that click over — offering it here would put a modal back over the pane that replaced it.+ * One way of opening it stands out — into the tab the map is in — and the rest are gathered behind+ * the button beside it. Three of them spread across the row read as three unrelated things when they+ * are one thing with three destinations, and the menu they are gathered into is the app's own, so+ * the pane offers exactly what a link offers anywhere else rather than a hand-kept subset of it.+ *+ * The quick editor is in that menu but not in the row: it is what a click on a marker used to raise,+ * and the pane took that click over — offering it here would put a modal back over the pane that+ * replaced it.*/function MarkerActions({ note, isReadOnly, onRelocate }: { note: FNote; isReadOnly: boolean; onRelocate(): void }) {const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);@@ -288,28 +353,43 @@ function MarkerActions({ note, isReadOnly, onRelocate }: { note: FNote; isReadOnreturn (<div className="geo-detail-pane-actions">- <ActionButton- icon="bx bx-log-in"- text={t("geo-map.open-note")}- // Handed the event: `openInCurrentNoteContext` reads the target tab off the element- // clicked, which lands the note in the tab the map is in.- onClick={(e) => notePath && openInCurrentNoteContext(e as MouseEvent, notePath)}- disabled={!notePath}- />-- <ActionButton- icon="bx bx-link-external"- text={t("link_context_menu.open_note_in_new_tab")}- onClick={() => notePath && appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId })}- disabled={!notePath}- />+ <ButtonGroup className="geo-detail-pane-open">+ <Button+ className="geo-detail-pane-open-note"+ // Flat, as everything else in the row is: a filled button beside five bare icons+ // reads as the one thing on the pane worth pressing, which it is not.+ kind="lowProfile"+ size="small"+ icon="bx-log-in"+ text={t("geo-map.open-note")}+ // Handed the event: `openInCurrentNoteContext` reads the target tab off the+ // element clicked, which lands the note in the tab the map is in.+ onClick={(e) => notePath && openInCurrentNoteContext(e as MouseEvent, notePath)}+ disabled={!notePath}+ />- <ActionButton- icon="bx bx-window-open"- text={t("link_context_menu.open_note_in_new_window")}- onClick={() => notePath && appContext.triggerCommand("openInWindow", { notePath, hoistedNoteId })}- disabled={!notePath}- />+ <Dropdown+ buttonClassName="dropdown-toggle-split tn-low-profile btn-sm"+ title={t("geo-map.more-ways-to-open")}+ noSelectButtonStyle+ noDropdownListStyle+ // The panel clips what overflows it, so a menu nested in the row would be cut off+ // at its edge; and the panel's backdrop filter would flatten the menu's own.+ portalToBody+ disabled={!notePath}+ >+ {OTHER_WAYS_TO_OPEN.map(({ command, icon, title }) => (+ <FormListItem+ key={command}+ icon={icon}+ onClick={(e) => notePath && linkContextMenu.handleLinkContextMenuItem(+ command, e as MouseEvent, notePath, {}, hoistedNoteId ?? null)}+ >+ {title()}+ </FormListItem>+ ))}+ </Dropdown>+ </ButtonGroup><ActionButtonicon="bx bx-map-alt"@@ -320,8 +400,26 @@ function MarkerActions({ note, isReadOnly, onRelocate }: { note: FNote; isReadOn/>{/* Left out rather than disabled on a read-only map, as the right-click menu leaves them- out: everything else in the row reads the note, these two alone write it. */}+ out: everything else in the row reads the note, these three alone write it. */}{!isReadOnly && <>+ {/* The colour the pin is drawn in, which the pane already wears in its title but had+ no way of setting — the right-click menu was the only place it could be reached.++ Sent to the body because the panel both clips what overflows it and carries a+ backdrop filter, either of which would be enough to cut the menu off or flatten+ its own frosting (see the Dropdown notes in CLAUDE.md). */}+ <Dropdown+ className="geo-detail-pane-color"+ buttonClassName="bx bx-palette"+ title={t("geo-map.marker-color")}+ iconAction+ hideToggleArrow+ noDropdownListStyle+ portalToBody+ >+ <NoteColorPicker note={note} />+ </Dropdown>+<ActionButtonclassName="geo-detail-pane-move"icon="bx bx-move"@@ -348,6 +446,28 @@ function MarkerActions({ note, isReadOnly, onRelocate }: { note: FNote; isReadOn);}+/**+ * The ways of opening a note other than in the tab one is already in, which the split hides behind+ * its arrow. The same four a link offers anywhere in the app, and each is carried out by the app's+ * own handler — only the naming of them is repeated here.+ *+ * Repeated because `linkContextMenu.getItems` asks for the event that raised it, which a menu drawn+ * before anything is pressed does not have. What it wants the event for is one mobile-only wording,+ * so the loss is a label rather than behaviour. The titles are thunks so they are translated when+ * the menu is drawn rather than when this module loads.+ */+export const OTHER_WAYS_TO_OPEN = [+ { command: "openNoteInNewTab", icon: "bx bx-link-external", title: () => t("link_context_menu.open_note_in_new_tab") },+ // The one the row never offered, and the one a map most wants: the place stays on show while the+ // note is read beside it.+ { command: "openNoteInNewSplit", icon: "bx bx-dock-right", title: () => t("link_context_menu.open_note_in_new_split") },+ { command: "openNoteInNewWindow", icon: "bx bx-window-open", title: () => t("link_context_menu.open_note_in_new_window") },+ // The quick editor, which is what a marker click used to raise before the pane took that click+ // over. Kept because the marker's own right-click menu offers it and the two should agree —+ // it is a way of opening the note that happens to stand over the pane, not a rival to it.+ { command: "openNoteInPopup", icon: "bx bx-edit", title: () => t("link_context_menu.open_note_in_popup") }+] as const;+/*** Where the marker stands, written out under the note's name.*diff --git a/apps/client/src/widgets/collections/geomap/api.ts b/apps/client/src/widgets/collections/geomap/api.tsindex ef13c91f32..7c3ed19806 100644--- a/apps/client/src/widgets/collections/geomap/api.ts+++ b/apps/client/src/widgets/collections/geomap/api.ts@@ -1,6 +1,5 @@import FNote from "../../../entities/fnote";import attributes from "../../../services/attributes";-import { prompt } from "../../../services/dialog";import { t } from "../../../services/i18n";import note_create from "../../../services/note_create";import type { GeoMouseEvent } from "./map";@@ -14,20 +13,26 @@ export async function moveMarker(noteId: string, latLng: { lat: number; lng: numawait attributes.setLabel(noteId, LOCATION_ATTRIBUTE, value);}+/**+ * Creates a note where the click landed, and hands it back for the pane to open on.+ *+ * No title is asked for first. A modal between the click and the note was the wrong way round: it+ * blocked the map to ask for the one thing the detail pane is made for editing. The note is created+ * under the stock name instead, and the caller opens the pane on it with that name selected — naming+ * the place is typing over it (see index.tsx).+ */export async function createNewNote(parentNote: FNote, e: GeoMouseEvent) {- const title = await prompt({ message: t("relation_map.enter_title_of_new_note"), defaultValue: t("relation_map.default_new_note_title") });+ const { note } = await note_create.createNote(parentNote.noteId, {+ title: t("relation_map.default_new_note_title"),+ content: "",+ type: "text",+ activate: false,+ isProtected: parentNote.isProtected,+ attributes: [+ { type: "label", name: LOCATION_ATTRIBUTE, value: [e.latlng.lat, e.latlng.lng].join(",") },+ { type: "label", name: "iconClass", value: CHILD_NOTE_ICON }+ ]+ });- if (title?.trim()) {- await note_create.createNote(parentNote.noteId, {- title,- content: "",- type: "text",- activate: false,- isProtected: parentNote.isProtected,- attributes: [- { type: "label", name: LOCATION_ATTRIBUTE, value: [e.latlng.lat, e.latlng.lng].join(",") },- { type: "label", name: "iconClass", value: CHILD_NOTE_ICON }- ]- });- }+ return note;}diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex a7b44cf4b9..0a55aa0bc5 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -19,7 +19,7 @@ import { useCollectionTreeDrag, useNoteBlob, useNoteLabel, useNoteLabelBoolean,import { ViewModeProps } from "../interface";import { createNewNote, moveMarker } from "./api";import ContextMenus from "./ContextMenus";-import DetailPane from "./DetailPane";+import DetailPane, { PaneSelection } from "./DetailPane";import GhostPin from "./GhostPin";import { GpxTrack } from "./GpxTrack";import Map, { GeoMouseEvent } from "./map";@@ -61,6 +61,9 @@ type Placement =export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewModeProps<MapData>) {const [ placement, setPlacement ] = useState<Placement>();+ // Which marker the detail pane stands for. Held here rather than in the pane so that creating a+ // note can open the pane on it (see createNoteAt below).+ const [ selection, setSelection ] = useState<PaneSelection | null>(null);const [ coordinates, setCoordinates ] = useState(viewConfig?.view?.center);const [ zoom, setZoom ] = useState(viewConfig?.view?.zoom);const [ hasScale ] = useNoteLabelBoolean(note, "map:scale");@@ -92,6 +95,24 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMconst startNotePlacement = useCallback(() => setPlacement({ mode: "new" }), []);const startMarkerRelocation = useCallback((noteId: string) => setPlacement({ mode: "move", noteId }), []);+ /**+ * Creates a note where the click landed and opens the pane on it, title selected, so naming the+ * place is typing over the stock name — there is no dialog between the click and the note (see+ * createNewNote). Serving both ways of asking for a note: the armed click and the right-click menu.+ *+ * The note is put among the map's own before the pane is pointed at it. It is already a child —+ * the collection just has not reloaded around it yet — and the pane closes itself over a+ * selection it cannot find, so waiting for the reload would open the pane on a note it refuses.+ * The marker appears with the pane rather than after it, which is no accident either.+ */+ const createNoteAt = useCallback(async (e: GeoMouseEvent) => {+ const created = await createNewNote(note, e);+ if (!created) return;++ setNotes((current) => current.some((n) => n.noteId === created.noteId) ? current : [ ...current, created ]);+ setSelection({ noteId: created.noteId, isNew: true });+ }, [ note ]);+// Placement mode is armed by the button or by the context menu. Tying the instruction toast and// the global Escape-to-cancel listener to the state (rather than the handler that armed it)// guarantees both are torn down on cancel, on completion (map click) and on unmount — otherwise@@ -140,11 +161,11 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMsetPlacement(undefined);if (placement.mode === "new") {- await createNewNote(note, e);+ await createNoteAt(e);} else {await moveMarker(placement.noteId, e.latlng);}- }, [ note, placement ]);+ }, [ placement, createNoteAt ]);// Draggingconst containerRef = useRef<HTMLDivElement>(null);@@ -213,8 +234,8 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMbeing moved wearing its own pin, a note to be created wearing the pin it will begiven (see api.ts). */}{placement && <GhostPin note={placement.mode === "move" ? notes.find((n) => n.noteId === placement.noteId) : undefined} />}- <DetailPane notes={notes} placing={!!placement} isReadOnly={isReadOnly} onRelocate={startMarkerRelocation} />- <ContextMenus note={note} isReadOnly={isReadOnly} onRelocate={startMarkerRelocation} />+ <DetailPane notes={notes} placing={!!placement} isReadOnly={isReadOnly} selection={selection} onSelect={setSelection} onRelocate={startMarkerRelocation} />+ <ContextMenus isReadOnly={isReadOnly} onRelocate={startMarkerRelocation} onCreateNote={createNoteAt} />{/* The pane above is what a click on a marker opens now, so the markers no longeropen the note themselves — the two would otherwise both answer the same click,raising the quick editor over the pane that had just opened behind it. */}diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsxindex 2c7bf45724..04c19e5a3b 100644--- a/apps/client/src/widgets/react/Button.tsx+++ b/apps/client/src/widgets/react/Button.tsx@@ -1,4 +1,4 @@-import type { ComponentChildren, CSSProperties, RefObject } from "preact";+import type { ComponentChildren, CSSProperties, JSX, RefObject } from "preact";import { useMemo } from "preact/hooks";import { CommandNames } from "../../components/app_context";@@ -17,8 +17,14 @@ export interface ButtonProps {className?: string;icon?: string;keyboardShortcut?: string;- /** Called when the button is clicked. If not set, the button will submit the form (if any). */- onClick?: () => void;+ /**+ * Called when the button is clicked. If not set, the button will submit the form (if any).+ *+ * Handed the event, which the button already forwarded before this said so: some handlers read+ * the press's own target to know where to act — opening a note in the tab the button stands in,+ * for one (see `openInCurrentNoteContext`).+ */+ onClick?: JSX.MouseEventHandler<HTMLButtonElement>;kind?: "primary" | "secondary" | "lowProfile";disabled?: boolean;size?: "normal" | "small" | "micro";diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsxindex e053be214a..aaca7b1cc5 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx@@ -129,7 +129,10 @@ export default function ShortcutSettings() {/>}<Buttontext={t("shortcuts.reload_app")}- onClick={reloadFrontendApp}+ // Called rather than handed over: its one argument is the reason to be+ // logged for the reload, and passed straight to the button that would+ // have been the click event.+ onClick={() => reloadFrontendApp()}size="micro"/><Button