Skip to content

Reload the document from disk on demand (⌘R) - #37

Merged
b451c merged 1 commit into
b451c:mainfrom
rinh:feature/reload
Oct 22, 2026
Merged

b451c merged 1 commit into
b451c:mainfrom
rinh:feature/reload

Conversation

@rinh

@rinh rinh commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

What

A manual Reload for the rendered view: View ▸ Reload (⌘R) and a ↻ pill in the top-right cluster, next to Edit.

Why

Auto-reload depends on file-system events. Some network volumes and some editors' save strategies never deliver them. When that happens, the only way to see the current text today is to close the document and open it again.

How

  • reloadManually() in MarkdownView reuses reloadFromDisk() (same decoding and line-ending normalization as the first load), then calls startWatching(url) again so a watcher that lost track of the file starts working again.
  • A toast says what happened: "Reloaded" or "Reloaded · no changes". If the file is gone, the existing "File no longer exists" banner shows instead.
  • Disabled while Source Edit shows. In that mode the session already follows the disk and owns the conflict banner (S-D9), so a second path to the same file would race it.
  • Routed through @FocusedValue (reloadDocumentAction) like the other per-document commands, so ⌘R acts on the frontmost tab only. ⌘R was unused (⌘⇧R is Reading Mode).
  • The pill is hidden in Reading Mode and for untitled documents, matching the Edit pill.
  • CHANGELOG ([Unreleased]) and the README's "Works with Your Editor" section have a line each.

Testing

  • xcodebuild … test: everything passes except ExternalEditorLineTests.testAppDisplayNameHasNoAppExtension. That test also fails on main on a Mac set to Chinese, because TextEdit's localized display name is "文本编辑". It is unrelated to this change and passes under an English locale such as CI.
  • Release build, plus the -DAPPSTORE build: both succeed.
  • Manual check: appended a line to an open file, pressed ⌘R, then ⌘A ⌘C. The new line was in the copied text. View ▸ Reload is enabled in the rendered view.

🤖 Generated with Claude Code

Auto-reload relies on file-system events, which some network volumes and
editors' save strategies never deliver; the only way back to the current
text was closing and reopening the document. View ▸ Reload (⌘R) and a ↻ pill
in the top-right cluster re-read the file now and restart the watcher, so a
watcher that lost track of the file recovers too.

A toast says whether anything changed ("Reloaded" / "Reloaded · no
changes"); a missing file shows the existing "File no longer exists" banner.
Disabled while Source Edit shows: the session already follows the disk and
owns the conflict banner, so a second path to the same file would race it.

Routed through @focusedvalue like every other per-document command, so ⌘R
acts on the frontmost tab only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@b451c
b451c merged commit f4ab5d2 into b451c:main Oct 22, 2026
3 checks passed
@b451c

b451c commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Thank you, @rinh - merged. Reload on demand is a good fit, and the pill stays.

A follow-up commit (77c98cf) handles three edge cases found in review and checked on a build:

  • A file that exists but cannot be read (a stalled network volume, chmod 000, a sandbox denial) used to show "Reloaded - no changes", because decoding never fails (Latin-1 fallback) and the text compared equal. It now says "Couldn't read the file".
  • On a missing file, the watcher is now restarted too, so the banner clears by itself when the file comes back. Before, it stayed until the next manual reload.
  • The watcher is restarted before the read, so a write that lands in between is not lost.

Thanks also for flagging the TextEdit test under a Chinese locale. It now checks the English name only when English is the first preferred language (7c325f5). This goes out in the next release.

@b451c

b451c commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Shipped in v1.13.0: https://github.com/b451c/quickmd/releases/tag/v1.13.0 (also on Homebrew). Thanks again, @rinh!

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.

2 participants