fix(editor): re-highlight the document after a programmatic text replacement (#1612)#1615
Closed
datlechin wants to merge 1 commit into
Closed
fix(editor): re-highlight the document after a programmatic text replacement (#1612)#1615datlechin wants to merge 1 commit into
datlechin wants to merge 1 commit into
Conversation
Member
Author
|
Folded into #1616, which now targets main and carries both the fix and the refactor. |
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.
Fixes #1612.
Problem
Clicking Format replaced the query text and all syntax highlighting disappeared, never recovering. With #1611 merged, Format flows exclusively through the binding push-down (
syncBindingText->setText), which made the loss deterministic.Root cause, two layers
syncBindingTextcalled the TextView-leveltextView.setText(...), bypassingTextViewController.setText(_:), which is the documented controller-level path and rebuilds the highlighter for the replacement storage. The old highlighter kept tree-sitter state for the dead document.Highlighteronly queries when triggered (an edit, a frame/bounds notification, orinvalidate()). Initial load works because the first layout pass firesframeDidChangeNotification; after a mid-session storage swap no trigger is guaranteed, so the rebuilt highlighter sat idle and the document stayed plain.Fix
syncBindingTextroutes throughcontroller.setText(newValue)so the highlighter is rebuilt for the new storage.setUpHighlighter()now ends withhighlighter.invalidate(), making "after setup, the editor is highlighted" an invariant for every caller instead of a timing accident.Tests
test_syncRebuildsHighlighterForReplacementStorage: the highlighter instance is rebuilt on a binding push-down.test_syncQueriesHighlightsForReplacementStorage: a mock provider proves the rebuilt highlighter is re-set-up AND re-queried; this test fails with the route-through change alone.Note
The issue also asks for a minify counterpart to Format; that is a feature request and should be tracked separately.