Skip to content

fix: route Live Mode changes to the watched file - #296

Merged
alecdotdev merged 5 commits into
sftwrdotdev:masterfrom
PathGao:fix/live-mode-route-watched-path
Aug 1, 2026
Merged

fix: route Live Mode changes to the watched file#296
alecdotdev merged 5 commits into
sftwrdotdev:masterfrom
PathGao:fix/live-mode-route-watched-path

Conversation

@PathGao

@PathGao PathGao commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Fixes #295

Live Mode now tracks the active file at the window layer and carries the watched path in file-change events. An event for a background tab can no longer reload the active tab or discard its unsaved buffer. Enabling Live Mode no longer reloads the current document.

Depends on #293. Please merge in this order: #286#287#288#293 → this PR.

Validation:

  • npm ci
  • npm run check
  • npm test
  • cargo test

@PathGao

PathGao commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

@alecdotdev This is the next dependent safety fix after #293. It prevents Live Mode from reloading a different, dirty tab when a background watched file changes. All required checks pass; merge order is #286#293#296.

@PathGao
PathGao force-pushed the fix/live-mode-route-watched-path branch from b4b34df to 8cec9a9 Compare July 31, 2026 05:50
@PathGao

PathGao commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

The branch is now directly based on #293; please use the updated single-chain merge order in the PR description.

@alecdotdev
alecdotdev merged commit 09dca81 into sftwrdotdev:master Aug 1, 2026
5 checks passed
@PathGao
PathGao deleted the fix/live-mode-route-watched-path branch August 2, 2026 08:34
PathGao added a commit that referenced this pull request Aug 2, 2026
…ying work (#374)

**A truncated preview buffer could be written back over the whole file.**
Opening a document larger than 50 KB starts with
`open_markdown_preview(maxBytes: 50000)`, and `setTabRawContent` made that
partial text both the buffer and the baseline, with `isDirty=false` and
nothing marking it incomplete. The background full read is abandoned if the
tab changes mode or gets edited in the meantime, and `toggleSplitView` only
re-read when `!tab.rawContent` — a partial buffer is not empty, so it did
not. Anything that then wrote the buffer truncated the file at 50 KB.

Four routes reached that state, not one: entering split view, toggling a
task checkbox from reading mode, editing front matter from reading mode, and
`reloadFromDisk` (F5), which handed the editor itself a partial buffer.

A tab now records whether its buffer is partial, every editable entry point
completes it from disk first, and saving refuses a partial buffer as a
backstop. Detaching a tab to another window completes it too: the transfer
payload has no field for the flag and rebuilds the tab explicitly, so the
destination would have inherited a short buffer that looked authoritative,
with its own auto-save timer.

**An external change overwrote unsaved edits silently.** The watcher
listener checked live mode and the self-write grace window but never
`tab.isDirty`, and `setTabRawContent` rewrites `originalContent` too, so a
`git checkout`, a cloud sync, or another window saving the same file took
the edits with no trace that anything had been dirty. A dirty tab now raises
a conflict the user answers — reload, or keep mine — instead of reloading
under them.

The debounced auto-save is held back while a conflict is unanswered.
Otherwise the timer would write 1.5 s later and drop the external change
while the bar was still asking which version to keep. Explicit saves still
go through: pressing Save *is* the answer "keep mine", and the save path
clears the conflict so the bar comes down rather than re-asking. The
debounce is the only thing that ever writes without being asked, so it is
the only thing suppressed.

Live Mode itself needed no change here — #296 already made toggling it
install the watcher without reloading. The regression lock for that is kept
and now points at the new tests.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live Mode can reload the wrong tab after an external file change

2 participants