[shared] Fix Find highlights going stale after edits (#264)#293
Merged
Conversation
Clear find highlights on edit and surface a "stale" state in the find bar so the user knows to retype to refresh. ⌘G / Find Next re-runs the search when matches were cleared. Mac uses layout-manager temporary attributes so find backgrounds don't collide with `==highlight==` syntax; iOS keys removal on the find color value for the same reason. Also clears matches on external text replacement (file load/revert).
Two bugs surfaced after the initial #264 fix landed. Mac's `@Published.$query` sink re-read `findState.query` when it fired, but `@Published` publishes in willSet — so the read returned the OLD value and every search ran one keystroke behind; pass `newQuery` from the sink directly into `performFind`. Both platforms also painted find color onto `NSTextStorage`, which overwrote any `==highlight==` markdown background it landed on; Mac now uses `NSLayoutManager.addTemporaryAttribute` (Apple's pattern for transient UI highlights, doesn't touch storage), and iOS re-runs the syntax highlighter on apply/clear since UIKit's `NSLayoutManager` has no temp-attribute API.
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
NSLayoutManagertemporary attributes — Apple's documented pattern for transient UI highlights — so painting never touchesNSTextStorageand never collides with==highlight==markdown backgrounds; iOS re-runs the syntax highlighter on apply/clear (UIKit'sNSLayoutManagerhas no temp-attribute API).resultsAreStaleflag so the user knows to retype, and ⌘G / Find Next re-runs the search when matches were cleared.@PublishedwillSet timing bug where the Combine sink forstate.$queryre-readfindState.queryand got the OLD value, causing every search to run one keystroke behind —performFindnow takes the new query as a parameter.Fixes #264
Test plan
resultsAreStaleshows in find bar==highlighted==markdown, then close Find → yellow markdown background is intact