diff --git a/src/commands.test.ts b/src/commands.test.ts index c4a40c26..a5322fc2 100644 --- a/src/commands.test.ts +++ b/src/commands.test.ts @@ -608,6 +608,31 @@ describe("capture", () => { expect(said()).toEqual(["Timestamp added to Saved Episode", REFUSED]); }); + it("leaves the timestamp once another open editor of the note holds other text, and says so", async () => { + const { editor, openNote, read } = await intoEditor("Notes\n"); + const other = openNote("Journal.md", "Notes\nUnsaved in the other pane"); + + await undo(); + + expect(editor.getValue()).toBe("Notes\n- 00:20:34"); + expect(other.editor.getValue()).toBe("Notes\nUnsaved in the other pane"); + expect(read("Journal.md")).toBe("Notes\n"); + expect(said()).toEqual(["Timestamp added to Journal", REFUSED]); + }); + + it("takes the timestamp out when every open editor of the note holds it as captured", async () => { + const { editor, openNote } = await intoEditor("Notes\n"); + const other = openNote("Journal.md", editor.getValue()); + + await undo(); + + expect([editor.getValue(), other.editor.getValue()]).toEqual([ + "Notes\n", + "Notes\n- 00:20:34", + ]); + expect(said()).toEqual(["Timestamp added to Journal"]); + }); + it("takes the timestamp out through the episode note's open editor", async () => { const { plugin, notes, openNote, read } = await loadPlugin(playing); notes.set(NOTE_PATH, { file: vaultFile(NOTE_PATH), content: "# Mine\n" }); diff --git a/src/services/CaptureService.ts b/src/services/CaptureService.ts index 2e1e6a88..a9d2cf24 100644 --- a/src/services/CaptureService.ts +++ b/src/services/CaptureService.ts @@ -169,11 +169,18 @@ export class CaptureService { // An open editor's buffer is the note: a vault write behind it could lose what it // has not saved yet. Obsidian saves a note as it leaves editing, so once that save // lands, a closed tab or one in Reading view leaves the file as the note. - const editing = this.plugin.app.workspace - .getLeavesOfType("markdown") - .map((leaf) => this.editingView(leaf)) - .find((view) => view?.file === file); - if (editing) return revertIn(editing.editor, snapshot); + // Every open editor of the note has to hold the text as the capture left it. + const editing = this.plugin.app.workspace.getLeavesOfType("markdown").flatMap((leaf) => { + const view = this.editingView(leaf); + return view?.file === file ? [view] : []; + }); + const [first] = editing; + if (first) { + return ( + editing.every((view) => view.editor.getValue() === snapshot.after) && + revertIn(first.editor, snapshot) + ); + } try { await this.plugin.app.vault.process(file, (content) => { if (content !== snapshot.after) throw new Error("The note changed"); diff --git a/src/ui/PodcastView/Player.svelte b/src/ui/PodcastView/Player.svelte index 536db736..23748738 100644 --- a/src/ui/PodcastView/Player.svelte +++ b/src/ui/PodcastView/Player.svelte @@ -1,5 +1,4 @@