Repository navigation
fix(desktop): reload an unedited tab silently when its file changes on disk (#3652) - #5479
Merged
Merged
Conversation
…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]>
3 of 6 tasks
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]>
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.
Closes #3652
Summary
Silently reloading a file that changed on disk already existed, but it was gated behind the
autoSavepreference, which defaults tofalse. 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:autoSaveoffautoSaveonA 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:
Compare/Overwrite). Requests for an opt-out (#41250, #23107) have not been implemented.Why not tie it to
autoSaveautoSavewrites MarkText's buffer back to disk afterautoSaveDelaywhenever 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
Test plan
Unit —
test/unit/specs/file-change-content-check.spec.tscovers the wholechangebranch. The reload test asserts the real outcome (tab.markdownactually updated) rather than spying onloadChange, and was verified RED against the old gate:autoSaveoff → reloads silently, no notification, tab stays savedautoSaveon → still prompts (guards against the overwrite above)E2E —
test/e2e/issue-3652-auto-reload.spec.ts(new) drives the real chokidar watcher with actualfs.writeFileSynccalls, 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.tsneeded 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 test830 passed ·pnpm run typecheckclean ·pnpm run lint0 errors · the three e2e specs above pass locally.Notes for reviewers
autoReloadpreference (+132 lines across schema, 11 locales, the General pane and the docs). Making it the default behavior instead needs no preference surface at all.Compare; we discard local edits on Yes.awaitWriteFinish.stabilityThreshold = 1000, plus polling on macOS).🤖 Generated with Claude Code