Skip to content

fix(desktop): reload an unedited tab silently when its file changes on disk (#3652) - #5479

Merged
Jocs merged 3 commits into
developfrom
fix/3652-auto-reload-clean-tab
Sep 21, 2026
Merged

Jocs merged 3 commits into
developfrom
fix/3652-auto-reload-clean-tab

Conversation

@Jocs

@Jocs Jocs commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Closes #3652

Summary

Silently reloading a file that changed on disk already existed, but it was gated behind the autoSave preference, which defaults to false. Anyone using MarkText as a preview window next to another editor (neovim, an AI tool, an MD logger) therefore got a "x" has been changed on disk. Do you want to reload it? prompt on every external save.

Reload now depends on the tab, not on autoSave:

Tab state Before After
No local edits, autoSave off prompt silent reload
No local edits, autoSave on silent reload silent reload
Unsaved edits prompt prompt
Content byte-identical (#1861) ignored ignored

A tab the user never edited discards nothing when it reloads, so it does not need confirmation. loadChange() already preserves the scroll position and keeps one history entry, so the old document is still one undo away.

Why not a preference

This is what both reference implementations do, and neither exposes a setting for it:

  • VS Code silently reloads a clean editor and only surfaces a conflict on save for a dirty one (Compare / Overwrite). Requests for an opt-out (#41250, #23107) have not been implemented.
  • Typora reloads automatically with no preference at all — typora-issues#2617 is someone looking for the setting.

Why not tie it to autoSave

autoSave writes MarkText's buffer back to disk after autoSaveDelay whenever the buffer is dirty (LISTEN_FOR_CONTENT_CHANGE). In the workflow this issue is about, a stray keystroke in the preview window would make the tab dirty and, five seconds later, overwrite whatever the other editor had just saved. The two directions should not share one switch.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added
  • Manually verified on macOS via the e2e suite driving the real watcher

Unit — test/unit/specs/file-change-content-check.spec.ts covers the whole change branch. The reload test asserts the real outcome (tab.markdown actually updated) rather than spying on loadChange, and was verified RED against the old gate:

AssertionError: expected 'hello' to be 'hello world'

E2E — test/e2e/issue-3652-auto-reload.spec.ts (new) drives the real chokidar watcher with actual fs.writeFileSync calls, for both directions: a clean tab takes the new text with no banner and no unsaved marker; a tab with unsaved edits gets the banner and keeps its edits.

test/e2e/issue-1861-filechange.spec.ts needed its positive control updated — it wrote different bytes and asserted the tab turned unsaved, which is exactly the behavior being replaced. It now asserts the new text reached the editor. Flipping it to "stays clean" instead would have made both halves of that test claim the same thing.

Both e2e files were verified by disabling the silent-reload branch and re-running: the #1861 positive control and the clean-tab case fail, the unsaved-tab case stays green.

pnpm run test 830 passed · pnpm run typecheck clean · pnpm run lint 0 errors · the three e2e specs above pass locally.

Notes for reviewers

  • Supersedes feat: add auto-reload preference for external file changes (#3652) #5458, which solved the same issue with a new opt-in autoReload preference (+132 lines across schema, 11 locales, the General pane and the docs). Making it the default behavior instead needs no preference surface at all.
  • Not covered here, and worth a separate issue: the dirty-tab conflict is still a bare Yes/No prompt. VS Code offers Compare; we discard local edits on Yes.
  • The watcher is unchanged, so a reload still lands ~1s after the external write (awaitWriteFinish.stabilityThreshold = 1000, plus polling on macOS).

🤖 Generated with Claude Code

…n disk (#3652)

Silently reloading a file that changed on disk was gated behind the
`autoSave` preference, which defaults to off. Everyone using MarkText as a
preview window next to another editor therefore got a "has been changed on
disk. Do you want to reload it?" prompt on every external save, and the only
way out was to turn on a preference that writes in the opposite direction.

Reload now depends on the tab instead of on `autoSave`: a tab with no local
edits discards nothing when it reloads, so it reloads without asking. A tab
with unsaved edits keeps the existing confirmation. This is what VS Code and
Typora both do, and neither offers a preference for it.

Tying the two together was also unsafe for the reported workflow. `autoSave`
writes MarkText's buffer back to disk after `autoSaveDelay`, so a stray
keystroke in the preview window would overwrite whatever the other editor
had just saved.

Also drops the `tab.isSaved = false` that ran before the prompt: only a tab
that is already unsaved reaches it now.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Build artifacts for PR #5479:

Run: https://github.com/marktext/marktext/actions/runs/35558040229

Artifact Size Link
marktext-windows-arm64 279.5 MB Download
marktext-linux 638.4 MB Download
marktext-macos-x64 297.9 MB Download
marktext-windows-x64 287.7 MB Download
marktext-macos-arm64 287.5 MB Download

Jocs and others added 2 commits September 21, 2026 11:35
The positive control wrote different bytes and asserted the tab turned
unsaved. A clean tab now reloads silently instead, so that assertion was
checking the behavior this branch just replaced.

Assert the new text reached the editor instead. That keeps the control
meaningful: if the assertion had simply flipped to "stays clean", both halves
of the test would claim the same thing and the guard could be deleted without
either of them noticing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Drives the real watcher for the two cases the fix distinguishes: a tab with
no local edits takes the new content with no banner and no unsaved marker,
and a tab holding unsaved edits gets the banner with its edits left alone.

Verified by disabling the silent-reload branch and re-running: the clean-tab
case fails, the unsaved-tab case stays green, which is what makes it a
regression guard rather than a restatement of the fix.

The banner assertion matches the interpolated filename because the message
itself is localized.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Jocs
Jocs merged commit 445912a into develop Sep 21, 2026
11 checks passed
@Jocs
Jocs deleted the fix/3652-auto-reload-clean-tab branch September 21, 2026 15:31
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.

auto-reload

1 participant