Skip to content

Conversation

angelosilvestre
Copy link
Collaborator

@angelosilvestre angelosilvestre commented Jul 25, 2025

[SuperEditor][SuperReader][SuperTextField] Merge stylesheet styles with default text style. (Resolves #2727)

Currently, SuperEditor, SuperReader and SuperTextField don't honor the enclosing DefaultTextStyle, which mean we cannot override the font family globally.

This PR adds that ability.

EDIT: This was made as an opt-in feature for all widgets to avoid silently changing the styles for people that are relying on the currently no-inheriting behavior.

@angelosilvestre
Copy link
Collaborator Author

angelosilvestre commented Jul 25, 2025

EDIT: I made it opt-in for SuperTextField also.

@matthew-carroll It seems some SuperTextField tests failed, so maybe we should indeed make this opt-in in SuperTextField also? If not, we would need to override the default text style of the existing tests.

InlineWidgetBuilderChain inlineWidgetBuilders,
) {
InlineWidgetBuilderChain inlineWidgetBuilders, {
bool inheritDefaultTextStyle = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this is too low level of a location to instruct the method to inherit the default text style. I know we provide a BuildContext but I'm wondering if it makes sense for this generic extension to have a concept of inheriting a text style. Would it make more sense for the caller to pass that in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense. Updated it.

);
});

testWidgetsOnArbitraryDesktop('inherits the enclosing default text style if requested', (tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that rebuilds the tree with a different style and makes sure that the new value is used after the pump?

Please do the same for SuperReader and SuperTextField.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already added a "changes visual text when the enclosing default text style changes" to each of them.

SingleColumnStylesheetStyler({
required Stylesheet stylesheet,
}) : _stylesheet = stylesheet;
TextStyle? defaultTextStyle,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a constructor Dart Doc that explains what should be passed for defaultTextStyle and what happens if nothing is passed for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

super.didChangeDependencies();

if (_docLayoutPresenter == null) {
_createLayoutPresenter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this conditional logic, can we create the layout presenter with a null default text style and then update it here without any conditional at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this logic because there are some situations where we re-create the presenter inside didUpdateWidget. For example, when the stylesheet changes.

It we always create the presenter with a null default textstyle, then we need to replicate the code that sets the default text style everywhere we create the presenter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't follow that explanation. Can you provide an example of what you mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first code snippet you included doesn't seem to reference the layout presenter at all. The second code snippet calls a method to create the layout presenter. Neither of these code snippets appear to show code that would need to be changed?

It would be great if you could show exactly what code snippet exists now, and exactly what code snippet it would need to become, so that we can avoid any confusion about what you're trying to say.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both snippets call _createLayoutPresenter. Each one would need to change to the following:

_createLayoutPresenter();
_docStylesheetStyler.defaultTextStyle = DefaultTextStyle.of(context).style;

/// and builds a corresponding inline widget.
///
/// If [defaultTextStyle] is non-`null`, the resulting [TextStyle]s
/// will be merged with it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to never say "merged" because it always begs the question as to which style wins out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SuperEditor][SuperReader][SuperTextField] - Ensure GoldenBricks can be used in golden tests
2 participants