text: Add code_block_highlighter to the component TextView - #3323
Closed
madcodelife wants to merge 1 commit into
Closed
madcodelife wants to merge 1 commit into
madcodelife wants to merge 1 commit into
Conversation
The Base `TextView` accepts a per-view code block highlighter, but the component `TextView` only highlighted through the application default installed from the theme, so one view could not render its code blocks plainly (or differently) while the rest kept syntax highlighting. The new builder mirrors the Base one and takes precedence over both the application default and the highlight theme of `.style(...)`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The Base
TextViewtakes a per-view code block highlighter, but the componentTextView(gpui_kit::component::text::TextView) only highlights through the application default that component initialization installs from the theme. A view could not show its code blocks as plain text, or highlight them differently, while other views keep the default.This adds the same builder to the component
TextView. It takes precedence over the application default and over thehighlight_themeof a style passed to.style(...). Returning no ranges renders that view's code blocks unhighlighted:Views without the builder are unchanged.
Public API
gpui-component
TextView::code_block_highlighter<F>(self, highlighter: F) -> Self where F: Fn(&CodeBlock) -> Vec<(Range<usize>, HighlightStyle)> + Send + Sync + 'static— highlights this view's fenced code blocks withhighlighterinstead of the application default or the style's highlight theme; same signature and range contract asgpui_base::TextView::code_block_highlighter.How to test
cargo test -p gpui-component --features tree-sitter --lib text::—code_block_highlighter_replaces_the_default_for_one_viewrenders two views side by side with a recording default highlighter: the view without an override is highlighted by the default only, the overridden view (which also sets a custom highlight theme) by its override only. The test fails if the override is not applied.Checklist
cargo clippy -p gpui-component --all-targets -- --deny warnings, with and withouttree-sitter.cargo runfor story tests related to the changes (no story change).