Address issue #110: Watch local resources and refresh on change#327
Merged
Conversation
Add file watching for local images, video, audio, and other resources referenced in the markdown preview. When a watched file changes on disk, append a cache-busting timestamp to its URL and re-render the preview. - MPFileWatcher: reusable single-file watcher (extracts dispatch source pattern from MPDocument) - MPResourceWatcherSet: manages a diffable set of file watchers - MPHTMLResourceURLs: extract local file paths from HTML and apply cache-busting query parameters - Refactor MPDocument to use MPFileWatcher for document auto-reload - Integrate resource watching into the render pipeline Related to #110
Atomic writes (atomically:YES) create a temp file and rename it, which triggers DISPATCH_VNODE_RENAME instead of DISPATCH_VNODE_WRITE. Use atomically:NO so the in-place write triggers the expected event. Related to #110
Remove redundant testHandlerReceivesCorrectPath (it still had atomically:YES and duplicated testHandlerCalledOnFileWrite). Increase dispatch_after delays to 0.2s and timeouts to 5s for CI runners under load. Related to #110
- Move updateWatchedPaths call before the DOM replacement / full reload split so newly added image references are watched immediately - Handle directory base URLs (unsaved documents) correctly in MPResolveLocalPath — check hasDirectoryPath before stripping filename - Add test for directory base URL case Related to #110
Contributor
Code Coverage ReportCurrent Coverage: 56.33% Coverage Details (Summary) |
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.
Summary
DISPATCH_SOURCE_TYPE_VNODE), extracted from inline code in MPDocument?t=<timestamp>query parametersWhen a local resource (image, video, audio, CSS) referenced in the Markdown preview is modified on disk, the preview now automatically refreshes to show the updated content.
Related Issue
Related to #110
Supersedes #305 (rebased to resolve merge conflicts with main)
Manual Testing Plan
photo.pngexternally (e.g., in Preview or with an image editor)<video src="clip.mp4">,<audio src="sound.mp3">,<link href="style.css">https://...) do not trigger file watchingReview Notes