Repository navigation
fix(capture): offer Undo in a focused popout and put the caret back on Undo - #502
Merged
Merged
Conversation
… a column J-TS-21 opens a draft in a popout, focuses that window and captures. The capture saves, but on master the popout's notice reads "[object DocumentFragment]" and has no Undo button. Two journeys type into a table cell of a two-row table, with the table in view and with it scrolled out of view, capture, Undo and capture again. The capture widens the column, so Obsidian pads the row below too. On master the Undo leaves the caret before the table header, and the second capture lands there and breaks the table. A third journey clicks into a cell of a note in a focused popout, lets the cell go stale in Source mode, changes another row on disk, captures and clicks Undo in the popout. It covers popout cells, which no journey did before. On master the capture keeps the table, and the journey stops at the missing Undo button.
With a popout focused, Obsidian shows a Notice in that popout, but reads its message with the main window's helpers. They take a DocumentFragment only from the main window, and show any other message as its String(). The notice was built from activeDocument, the popout's document, so it read "[object DocumentFragment]" and had no Undo. createFragment builds in the main window, and Obsidian moves the fragment into the popout, where Undo works. Fixes #498
A capture into a table cell can widen its column, and Obsidian then pads every row. Undo puts back the stretch the capture changed, which then runs from the table's first changed row past the cell, so it holds the caret, and CodeMirror moves the caret to the stretch's start. The same edit makes Obsidian redraw the table and end the cell's editor. The next capture then went before the table header and broke the table. A capture now keeps the selections of the editor it went into, and Undo restores them after its edit, in that editor while it still edits the note. The note is still put back only while it is exactly as the capture left it. Fixes #499
…ed popout's notice Undo restored the selections a capture found into whichever editor it reverted in. With the capturing tab closed and another tab of the note open, that moved the other tab's caret. The snapshot now keeps the caret with the editor it came from, and Undo restores it only there. A popout that closes while its Undo notice shows keeps the notice in its document, so the button stayed connected and the notice was checked every second for good. The check now also ends once the button's document has no window. Unit tests cover both, and that the notice is built in the main window. The table journey scrolled out of view now scrolls until the table leaves the viewport, as CodeMirror can scroll back to the cell first. The new e2e helpers say what they do in their names.
Deploying podnotes with
|
| Latest commit: |
a504835
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ee1f6e93.podnotes.pages.dev |
| Branch Preview URL: | https://fix-capture-undo-popout.podnotes.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #498
Fixes #499
Why
This fixes two capture Undo defects. With a popout focused, a capture saved, but its notice read "[object DocumentFragment]" and had no Undo. Obsidian shows the notice in the popout, but only takes a fragment built in the main window. After Undo of a capture that widened a table column, the caret sat before the table, so the next capture broke the table. Obsidian pads every row as the column widens, so Undo's edit spans the caret, and CodeMirror moves the caret to the edit's start.
What changed
noticeWithUndobuilds its message withcreateFragment()in place ofactiveDocument. It also stops checking on a notice once the popout that shows it closes.Scope
Tradeoffs
Blast Radius
Every capture Undo and every Undo notice take this path, in the main window too. There the notice is unchanged, and Undo now also puts the caret back. Size: 102,969 gzip bytes, +53 over master, 31 under the budget.
Verification
npm run test:e2eon a fresh vault, Obsidian 1.14.4: 238 of 238 pass.Mutations, each run against the unit files for capture and the notice, and the target journeys:
activeDocument(master)createFragmentDocs at release
None. The docs do not mention capture Undo or popouts.
Before, master with a popout focused:
After:
Before, master after Undo and the next capture. The capture went before the header:
After:
Note
Medium Risk
Changes affect every capture Undo path and undo notices globally; behavior is well-covered by new unit and e2e tests but touches editor caret restoration and cross-window DOM.
Overview
Fixes capture Undo when a note is in a focused popout and when table column padding moves the caret after Undo.
Undo notices now build their DOM with Obsidian’s main-window
createFragment()instead of the focused window’s document, so popout notices show readable text and a working Undo button instead of[object DocumentFragment]. Notice cleanup also stops polling once the popout window closes.Capture Undo snapshots the editor’s selections at capture time and restores them after reverting the text, so a widened-table undo that spans the caret no longer leaves the cursor before the table and breaks the next capture into the cell.
Tests cover popout-focused capture/undo, caret/selection restore (including multi-tab and table scenarios), and new e2e helpers for focusing and interacting with note popout windows.
Reviewed by Cursor Bugbot for commit a504835. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix capture Undo to restore editor caret and work in focused popouts
CaptureService.Snapshotand therevertInhelper in CaptureService.tsDocumentFragmentinstead of the active document, so Obsidian'sNoticeaccepts them while a popout is focused. The notice cleanup poll also stops when its popout document closes, preventing a leaked timernoticeWithUndoin undoNotice.ts if notice content ever depended on the active popout documentMacroscope summarized a504835.