gpui: Make refining a Style properly refine the TextStyle#42852
Merged
as-cii merged 8 commits intozed-industries:mainfrom Dec 15, 2025
Merged
gpui: Make refining a Style properly refine the TextStyle#42852as-cii merged 8 commits intozed-industries:mainfrom
Style properly refine the TextStyle#42852as-cii merged 8 commits intozed-industries:mainfrom
Conversation
Member
|
Please add a small GPUI test showing that this fixes the problem, perhaps in |
Style properly refine the TextStyle
The push_text_style call was made unconditional by this PR, but the corresponding pop_text_style remained conditional on text.is_some(). This caused the text style stack to become unbalanced when code_block.text had all None fields.
Member
|
Hey @Serophots, thanks for this pull request! I pushed a small fix and queued this up for merging! |
The font_features method was added after the PR branch diverged and used the old Option-based API. Updated to match the new direct TextStyleRefinement return type.
CherryWorm
pushed a commit
to CherryWorm/zed
that referenced
this pull request
Dec 16, 2025
…dustries#42852) ## Motivating problem The gpui API currently has this counter intuitive behaviour ```rust div() .id("hallo") .cursor_pointer() .text_color(white()) .font_weight(FontWeight::SEMIBOLD) .text_size(px(20.0)) .child("hallo") .active(|this| this.text_color(red())) ``` By changing the text_color when the div is active, the current behaviour is to overwrite all of the text styling rather than do a proper refinement of the existing text styling leading to this odd result: The button being active inadvertently changes the font size. https://github.com/user-attachments/assets/1ff51169-0d76-4ee5-bbb0-004eb9ffdf2c ## Solution Previously refining a Style would not recursively refine the TextStyle inside of it, leading to this behaviour: ```rust let mut style = Style::default(); style.refine(&StyleRefinement::default().text_size(px(20.0))); style.refine(&StyleRefinement::default().font_weight(FontWeight::SEMIBOLD)); assert!(style.text_style().unwrap().font_size.is_none()); //assertion passes ``` (As best as I can tell) Style deliberately has `pub text: TextStyleRefinement` storing the `TextStyleRefinement` rather than the absolute `TextStyle` so that these refinements can be elsewhere used in cascading text styles down to element's children. But a consequence of that is that the refine macro was not properly recursively refining the `text` field as it ought to. I've modified the refine macro so that the `#[refineable]` attribute works with `TextStyleRefinement` as well as the usual `TextStyle`. (Perhaps a little bit haphazardly by simply checking whether the name ends in Refinement - there may be a better solution there). This PR resolves the motivating problem and triggers the assertion in the above code as you'd expect. I've compiled zed under these changes and all seems to be in order there. Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.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.
Motivating problem
The gpui API currently has this counter intuitive behaviour
By changing the text_color when the div is active, the current behaviour is to overwrite all of the text styling rather than do a proper refinement of the existing text styling leading to this odd result:
The button being active inadvertently changes the font size.
Screen.Recording.2025-11-16.at.10.51.32.pm.mov
Solution
Previously refining a Style would not recursively refine the TextStyle inside of it, leading to this behaviour:
(As best as I can tell) Style deliberately has
pub text: TextStyleRefinementstoring theTextStyleRefinementrather than the absoluteTextStyleso that these refinements can be elsewhere used in cascading text styles down to element's children. But a consequence of that is that the refine macro was not properly recursively refining thetextfield as it ought to.I've modified the refine macro so that the
#[refineable]attribute works withTextStyleRefinementas well as the usualTextStyle. (Perhaps a little bit haphazardly by simply checking whether the name ends in Refinement - there may be a better solution there).This PR resolves the motivating problem and triggers the assertion in the above code as you'd expect. I've compiled zed under these changes and all seems to be in order there.
Release Notes: