Skip to content

Fix selection highlight artifacts for faded selectable text#183628

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
ikramhasan:fix_182776
May 15, 2026
Merged

Fix selection highlight artifacts for faded selectable text#183628
auto-submit[bot] merged 3 commits into
flutter:masterfrom
ikramhasan:fix_182776

Conversation

@ikramhasan

Copy link
Copy Markdown
Contributor

Summary

Fixes a rendering artifact when selecting text inside SelectionArea for a Text/RichText that uses TextOverflow.fade.

Previously, RenderParagraph painted selection highlights into the same saveLayer used for the fade overflow shader. That caused the fade compositing path to affect the selection rects and produced dark border/line artifacts during selection.

This change separates selection highlight painting from the faded text layer so the fade shader only applies to the text content.

Fixes: #182776

Changes

  • Paint RenderParagraph selection highlights outside the overflow fade saveLayer

Screenshots

Before After
Before After

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a rendering artifact for faded selectable text by separating the painting of selection highlights from the text fading layer. The refactoring of _SelectableFragment into paintSelection and paintHandles is a good improvement for code clarity. I have one suggestion to improve the robustness of the canvas state management during painting.

Comment on lines +1021 to +1030
if (_needsClipping) {
context.canvas.save();
context.canvas.clipRect(offset & size);
}
for (final _SelectableFragment fragment in _lastSelectableFragments!) {
fragment.paintSelection(context, offset);
}
if (_needsClipping) {
context.canvas.restore();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

To ensure the canvas state is always restored even if an exception occurs during painting the selection, it's safer to wrap the painting logic in a try...finally block. This prevents leaving the canvas in a corrupted state if paintSelection throws an exception.

      if (_needsClipping) {
        context.canvas.save();
        context.canvas.clipRect(offset & size);
      }
      try {
        for (final _SelectableFragment fragment in _lastSelectableFragments!) {
          fragment.paintSelection(context, offset);
        }
      } finally {
        if (_needsClipping) {
          context.canvas.restore();
        }
      }

@Piinks Piinks added a: text input Entering text in a text field or keyboard related problems team-text-input Owned by Text Input team f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs labels Mar 17, 2026
@Renzo-Olivares Renzo-Olivares self-requested a review March 19, 2026 18:22
@Renzo-Olivares

Copy link
Copy Markdown
Contributor

Hi @ikramhasan, thank you for the fix! The approach looks good to me but I had a question. Also before moving forward with this change it will need a test to verify the expected behavior.


if (_lastSelectableFragments != null) {
for (final _SelectableFragment fragment in _lastSelectableFragments!) {
fragment.paintHandles(context, offset);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason why we separate the handles from the selection painting now? It makes sense in that we probably do not want to clip the handles when painting them but curious if there is another reason.

@ikramhasan

Copy link
Copy Markdown
Contributor Author

Hi @Renzo-Olivares sorry for the late reply. I was on my Eid vacation.

Is there a reason why we separate the handles from the selection painting now

It was split as I needed a way to paint the selection and handle separately. The previous paint function was doing both. This would cause the handles to get clipped with the selection/highlight as well.

Also before moving forward with this change it will need a test to verify the expected behavior.

Sure. It should be a golden test right?

@justinmc justinmc requested a review from Renzo-Olivares April 7, 2026 22:30
@Renzo-Olivares

Copy link
Copy Markdown
Contributor

@ikramhasan yeah a golden test feels appropriate here.

@Renzo-Olivares Renzo-Olivares left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall change LGTM, but we still need a test to land this.

@github-actions github-actions Bot removed the a: text input Entering text in a text field or keyboard related problems label Apr 15, 2026
@ikramhasan

Copy link
Copy Markdown
Contributor Author

Updated with a test @Renzo-Olivares

@Piinks

Piinks commented May 12, 2026

Copy link
Copy Markdown
Contributor

Hey @Renzo-Olivares could you have another look at this one?

Comment thread packages/flutter/test/rendering/paragraph_test.dart Outdated
Comment thread packages/flutter/test/rendering/paragraph_test.dart Outdated

@Renzo-Olivares Renzo-Olivares left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM w/ some small comments.

@Renzo-Olivares Renzo-Olivares added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 13, 2026
@ikramhasan

ikramhasan commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Updated the test with your feedback @Renzo-Olivares

@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 13, 2026
@Renzo-Olivares Renzo-Olivares added the CICD Run CI/CD label May 13, 2026

@Renzo-Olivares Renzo-Olivares left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, i'll find a secondary reviewer before landing this. Thank you for the contribution!

Heads up there is ci.yaml validation issues. git fetch upstream && git merge upstream/master should fix that.

@Renzo-Olivares Renzo-Olivares added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 13, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 13, 2026

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@Piinks Piinks added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels May 13, 2026
@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 13, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 13, 2026
@auto-submit

auto-submit Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/183628, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@Renzo-Olivares

Copy link
Copy Markdown
Contributor

Google testing failed but seems unrelated. Going to re-run.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label May 14, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue May 14, 2026
Merged via the queue into flutter:master with commit 1ceffd1 May 15, 2026
95 of 96 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 15, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request May 15, 2026
flutter/flutter@0541913...1ceffd1

2026-05-14 ikramhasan.dev@gmail.com Fix selection highlight artifacts for faded selectable text (flutter/flutter#183628)
2026-05-14 46920873+gabrimatic@users.noreply.github.com Fix nested Text.rich semantics order (flutter/flutter#186116)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…#11719)

flutter/flutter@0541913...1ceffd1

2026-05-14 ikramhasan.dev@gmail.com Fix selection highlight artifacts for faded selectable text (flutter/flutter#183628)
2026-05-14 46920873+gabrimatic@users.noreply.github.com Fix nested Text.rich semantics order (flutter/flutter#186116)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs framework flutter/packages/flutter repository. See also f: labels. team-text-input Owned by Text Input team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectionArea shows unexpected black line under overflowed text when focused

4 participants