From 614afb9f0f1d27df1091662c3d5fe009a7dc3323 Mon Sep 17 00:00:00 2001 From: Amp Date: Sat, 26 Sep 2026 20:37:15 +0000 Subject: [PATCH 1/2] fix(docs): name the target note in the geocoding prompt so Peek can't mislead quickAddApi.inputPrompt allows Peek by default, so users can open other notes while the address prompt is parked. The script already writes to the note that was active when the macro started; show that note's name in the prompt header and document the behaviour. Co-authored-by: Christian Bager Bach Houmann --- docs/public/scripts/getLongLatFromAddress.js | 5 +++- .../Macro_AddLocationLongLatFromAddress.md | 2 +- tests/examples/getLongLatFromAddress.test.ts | 25 ++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/docs/public/scripts/getLongLatFromAddress.js b/docs/public/scripts/getLongLatFromAddress.js index 4160272ab..bf509af28 100644 --- a/docs/public/scripts/getLongLatFromAddress.js +++ b/docs/public/scripts/getLongLatFromAddress.js @@ -4,13 +4,16 @@ module.exports = async (params) => { const {app, obsidian, quickAddApi} = params; + // The note open when the macro starts is the one that gets the location. + // Capture it now: the prompt's Peek lets the user open other notes (for + // example to copy the address) before submitting. const activeFile = app.workspace.getActiveFile(); if (!activeFile) { new obsidian.Notice("No active file", 5000); return; } - const address = await quickAddApi.inputPrompt("🏠 Address"); + const address = await quickAddApi.inputPrompt(`🏠 Address for ${activeFile.basename}`); if (!address) { new obsidian.Notice("No address given", 5000); return; diff --git a/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md b/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md index 7cb373e07..89e1416a0 100644 --- a/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md +++ b/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md @@ -29,7 +29,7 @@ location: 48.8582599,2.2945006 --- ``` -If the note already has a `location` property, the script replaces its value. If Nominatim finds no match, you get a notice and the note is left unchanged. +The prompt names the note it will update, for example **🏠 Address for Eiffel Tower**. That note gets the location even if you [peek](/docs/ControllingPrompts/#peek) and open another note, say to copy the address, before you submit. If the note already has a `location` property, the script replaces its value. If Nominatim finds no match, you get a notice and the note is left unchanged. ![The Eiffel Tower note's location property, and its pin in Map View](../Images/examples/macro-location-map-view.png) diff --git a/tests/examples/getLongLatFromAddress.test.ts b/tests/examples/getLongLatFromAddress.test.ts index 62e58635e..788c9206b 100644 --- a/tests/examples/getLongLatFromAddress.test.ts +++ b/tests/examples/getLongLatFromAddress.test.ts @@ -34,13 +34,19 @@ function run(options: { async (_file: unknown, fn: (fm: Record) => void) => fn(frontmatter), ); - const inputPrompt = vi.fn(async () => options.address); + const startFile = { path: "Places/Eiffel Tower.md", basename: "Eiffel Tower" }; + let activeFile: typeof startFile | null = + options.activeFile === false ? null : startFile; + const inputPrompt = vi.fn(async (_header: string) => { + // While the prompt is open, Peek lets the user open another note. + activeFile = { path: "Contacts/Venue.md", basename: "Venue" }; + return options.address; + }); const params = { app: { workspace: { - getActiveFile: () => - options.activeFile === false ? null : { path: "Place.md" }, + getActiveFile: () => activeFile, }, fileManager: { processFrontMatter }, }, @@ -62,6 +68,7 @@ function run(options: { requestUrl, processFrontMatter, inputPrompt, + startFile, }; } @@ -84,6 +91,18 @@ describe("getLongLatFromAddress example script", () => { expect(ctx.notices).toEqual([]); }); + it("writes to the note open when the macro started, even if another note is active on submit", async () => { + const ctx = run({ + address: "Eiffel Tower, Paris", + results: [{ lat: "48.8582599", lon: "2.2945006" }], + }); + await ctx.done; + + expect(ctx.inputPrompt).toHaveBeenCalledWith("🏠 Address for Eiffel Tower"); + expect(ctx.processFrontMatter).toHaveBeenCalledTimes(1); + expect(ctx.processFrontMatter.mock.calls[0][0]).toBe(ctx.startFile); + }); + it("replaces an existing location", async () => { const ctx = run({ address: "Colosseum, Rome", From 433b237c36d1c8ab34aeedbb31cb95e5b256098f Mon Sep 17 00:00:00 2001 From: Amp Date: Sat, 26 Sep 2026 20:55:42 +0000 Subject: [PATCH 2/2] fix(docs): show the note's vault path in the geocoding prompt Notes in different folders can share a basename; the path keeps the target unambiguous after a peek. Amp-Thread-ID: https://ampcode.com/threads/T-01a0df48-b10a-71ff-bdb9-a74681bbf152 Co-authored-by: Christian Bager Bach Houmann --- docs/public/scripts/getLongLatFromAddress.js | 2 +- .../docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md | 2 +- tests/examples/getLongLatFromAddress.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/public/scripts/getLongLatFromAddress.js b/docs/public/scripts/getLongLatFromAddress.js index bf509af28..ca5752cf1 100644 --- a/docs/public/scripts/getLongLatFromAddress.js +++ b/docs/public/scripts/getLongLatFromAddress.js @@ -13,7 +13,7 @@ module.exports = async (params) => { return; } - const address = await quickAddApi.inputPrompt(`🏠 Address for ${activeFile.basename}`); + const address = await quickAddApi.inputPrompt(`🏠 Address for ${activeFile.path}`); if (!address) { new obsidian.Notice("No address given", 5000); return; diff --git a/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md b/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md index 89e1416a0..a19af500b 100644 --- a/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md +++ b/docs/src/content/docs/docs/Examples/Macro_AddLocationLongLatFromAddress.md @@ -29,7 +29,7 @@ location: 48.8582599,2.2945006 --- ``` -The prompt names the note it will update, for example **🏠 Address for Eiffel Tower**. That note gets the location even if you [peek](/docs/ControllingPrompts/#peek) and open another note, say to copy the address, before you submit. If the note already has a `location` property, the script replaces its value. If Nominatim finds no match, you get a notice and the note is left unchanged. +The prompt names the note it will update, for example **🏠 Address for Places/Eiffel Tower.md**. That note gets the location even if you [peek](/docs/ControllingPrompts/#peek) and open another note, say to copy the address, before you submit. If the note already has a `location` property, the script replaces its value. If Nominatim finds no match, you get a notice and the note is left unchanged. ![The Eiffel Tower note's location property, and its pin in Map View](../Images/examples/macro-location-map-view.png) diff --git a/tests/examples/getLongLatFromAddress.test.ts b/tests/examples/getLongLatFromAddress.test.ts index 788c9206b..0552318d4 100644 --- a/tests/examples/getLongLatFromAddress.test.ts +++ b/tests/examples/getLongLatFromAddress.test.ts @@ -39,7 +39,7 @@ function run(options: { options.activeFile === false ? null : startFile; const inputPrompt = vi.fn(async (_header: string) => { // While the prompt is open, Peek lets the user open another note. - activeFile = { path: "Contacts/Venue.md", basename: "Venue" }; + activeFile = { path: "Contacts/Eiffel Tower.md", basename: "Eiffel Tower" }; return options.address; }); @@ -98,7 +98,7 @@ describe("getLongLatFromAddress example script", () => { }); await ctx.done; - expect(ctx.inputPrompt).toHaveBeenCalledWith("🏠 Address for Eiffel Tower"); + expect(ctx.inputPrompt).toHaveBeenCalledWith("🏠 Address for Places/Eiffel Tower.md"); expect(ctx.processFrontMatter).toHaveBeenCalledTimes(1); expect(ctx.processFrontMatter.mock.calls[0][0]).toBe(ctx.startFile); });