Skip to content

feat: add auto-reload preference for external file changes (#3652) - #5458

Closed
muchstarlight wants to merge 1 commit into
marktext:developfrom
muchstarlight:feat/3652-auto-reload
Closed

muchstarlight wants to merge 1 commit into
marktext:developfrom
muchstarlight:feat/3652-auto-reload

Conversation

@muchstarlight

Copy link
Copy Markdown

Closes #3652

Summary

Adds an opt-in Auto Reload preference so MarkText can silently reload a file when it changes on disk (external editor / AI tools / split-window preview).

Silent reload only runs when the tab has no unsaved edits. If the buffer is dirty, the existing “reload?” confirmation is kept so local work is not discarded.

This is intentionally not tied to Auto Save: Auto Save writes MarkText’s buffer back to disk and can overwrite the other editor. It is also not a read-only “Reading Mode”; the request is auto-reload while still being able to view/edit.

Default is false, so existing behavior is unchanged. The previous Auto Save silent-reload path is preserved.

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 (or explain why not needed)
  • Manually tested on: Windows

Unit tests in file-change-content-check.spec.ts cover:

Manual: Preferences → General → Auto Reload on, Auto Save off; edit the open file in another editor and save; MarkText updates without the reload dialog. Unsaved local edits still prompt.

Notes for reviewers

  • Preference key: autoReload (schema, preference.json, Pinia, General pane, all 11 locales, PREFERENCES.md)
  • Watcher / chokidar is unchanged; only the renderer reaction to mt::update-file is extended
  • Unsaved conflict still uses the existing tab notification, not a new UI
  • Non-English locale strings are provided for key-parity (locale-validation); happy to drop them to en.json if you’d rather route translations separately

新增 autoReload 选项(默认关闭)。标签页无未保存修改时,外部对文件的
写入会静默重载,不再弹出确认。未保存时仍确认,避免覆盖 MarkText 里的编辑。

不复用 autoSave:自动保存会把缓冲区写回磁盘,外编场景下可能覆盖对方刚写的内容。
@muchstarlight muchstarlight changed the title feat: 增加磁盘文件自动重载偏好 (#3652) feat: add auto-reload preference for external file changes (#3652) Sep 19, 2026
@Jocs

Jocs commented Sep 21, 2026

Copy link
Copy Markdown
Member

Thanks for taking this on, and sorry for the slow reply. Your diagnosis is the right one — in particular, calling out that auto-reload must not be tied to autoSave because autoSave writes our buffer back over the other editor. That is exactly the trap, and your PR description states it better than the issue does.

Where I ended up differing is on the preference. With autoReload defaulting to false, everyone who hits #3652 still hits it, and then has to discover a new checkbox to get out. Looking at what the two obvious reference implementations do:

  • VS Code silently reloads a clean editor, with no setting to opt in or out (#41250, #23107 are both still unimplemented).
  • Typora reloads automatically with no preference at all — typora-issues#2617 is someone hunting for the setting that does not exist.

Neither asks. A tab with no local edits discards nothing when it reloads, and our loadChange() already keeps the scroll position and one history entry, so the old document stays one undo away. That makes it a sound default rather than a feature to opt into.

So I went with the same behavior as the default, gated on isSaved instead of on a new preference: #5479. It is the same one-line decision you identified, minus the schema / preference.json / Pinia / General pane / 11 locales / PREFERENCES.md surface — 132 lines down to about 10.

Your test cases carried over almost as-is; I kept your four scenarios and changed the reload test to assert the real outcome (tab.markdown actually updated) instead of spying on loadChange, so it fails for the right reason. Credit for the coverage shape is yours.

Closing this in favor of #5479 — not because the work was wrong, but because the default moved. Please do keep them coming, and thank you for the careful write-up.

One thing #5479 deliberately does not touch, if you are looking for a follow-up: the dirty-tab conflict is still a bare Yes/No prompt that throws away local edits on Yes. VS Code offers Compare there. That would be a genuinely useful next PR.

@Jocs Jocs closed this Sep 21, 2026
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

2 participants