Markpad icon indicating copy to clipboard operation
Markpad copied to clipboard

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

Open PathGao opened this issue 4 months ago • 1 comments

Problem

Live Mode currently watches one file per window, but the watcher emits a pathless file-changed event. The frontend then reloads whichever tab is active at delivery time rather than the file that was watched.

This can overwrite unsaved edits in the active tab:

  1. Open A.md, then B.md.
  2. Enable Live Mode while B.md is active, so B.md is watched.
  3. Switch to A.md and make an unsaved edit.
  4. Modify B.md outside Markpad.
  5. The B.md watcher event reloads A.md; its in-memory buffer is replaced and its dirty state is cleared.

Root cause

src-tauri/src/window_runtime.rs emits file-changed with () and src/lib/MarkdownViewer.svelte reloads currentFile, which is derived from the active tab. The event has no way to identify the watched path.

Expected behavior

A file-change event must carry the watched path. The UI must reload only when that path is the active Live Mode document; an event for another tab must never replace the active tab's buffer.

Scope

Keep the single-watcher model. Route the watched path through the event and add a regression test for the cross-tab case.

PathGao avatar Jul 31 '26 05:07 PathGao

Tracked by #296. The regression test covers path-carrying watcher events, active-tab watcher ownership, and the no-reload Live Mode toggle behavior.

PathGao avatar Jul 31 '26 05:07 PathGao