Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Jun 27, 2023

Description

This PR fixes one selectable region test failure when switching to M3.
The failure is somewhat tricky because it is related to the M3 typography (line height set to 1.43).

Related Issue

fixes #129626

Tests

Updates 1 test.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Jun 27, 2023
@Renzo-Olivares
Copy link
Contributor

I think one issue here is that this case in

if (index == selectables.length - 1 && lastSelectionResult == SelectionResult.next) {
return SelectionResult.next;
}
should probably go above
if (lastSelectionResult == SelectionResult.next) {
continue;
}
, or else the first case will never get a chance to run which is why we see an assertion thrown.

if (index == selectables.length - 1 && lastSelectionResult == SelectionResult.next) {
  return SelectionResult.next;
}

if (lastSelectionResult == SelectionResult.next) {
  continue;
}
.
.
.

@Renzo-Olivares
Copy link
Contributor

Renzo-Olivares commented Jun 27, 2023

I haven't been able to find the root cause of this yet. The M3 Typography does set the height for TextStyle to 1.43 for bodyMedium which brings the issue to the surface. However, I think the issue being observed was also present before using useMaterial3: true.

If I try, and resize the window (I tried making it smaller). I am also not able to select the final Hello, world.

import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // theme: ThemeData.light(useMaterial3: true),
      home: Scaffold(
        body: SafeArea(
          child: Center(
            child: SelectionArea(
              child: Text.rich(
                  const TextSpan(
                      children: <InlineSpan>[
                        TextSpan(
                          text:
                              'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
                        ),
                        WidgetSpan(child: Text('Some text in a WidgetSpan. ')),
                        TextSpan(text: 'Hello, world.'),
                      ],
                  ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

I think we can do two things in this situation if we cannot find and fix the root cause in time.

  1. Merge this PR with the workaround and leave a TODO along with a link to the issue describing the problem.
  2. Merge this PR but instead of the workaround just skip the test in question and leave a TODO with an issue linked.

@goderbauer
Copy link
Member

(Triage): @bleroux Do you still have plans to follow up on the feedback given above?

@bleroux
Copy link
Contributor Author

bleroux commented Jul 26, 2023

(Triage): @bleroux Do you still have plans to follow up on the feedback given above?

Yes, I will soon update this PR as proposed in #129627 (comment).
The first step will be to file a more detailed issue that will be linked from a TODO in the updated PR.

@bleroux
Copy link
Contributor Author

bleroux commented Aug 1, 2023

@Renzo-Olivares , revisiting this, I wonder if the issue is only related to how the test is written.
Using a golden image we can have a better understanding of what happens.

image

The test simulates a right click on the word ‘Hello,’.

  • To get the click position the test relies on the textOffsetToPosition helper function which relies on Paragraph.getOffsetForCaret.
  • Paragraph.getOffsetForCaret returns the offset at the top left of a glyph (which means above the vertical space induced by the line height).
  • So the position used to simulate the click is not on the text but above it.
  • MultiSelectableSelectionContainerDelegate.handleSelectWorld relies on selectable fragments bounds to check if the mouse event position is inside the bounds of one of the selectable fragments. But the bounds of those fragments are the ones around the text (line height induced vertical spaces are not part of those bounds).

So my question for you is “‘should MultiSelectableSelectionContainerDelegate allow selection above and below the text when lineHeight is set?”.
If the answer is no, the test should adjust the gesture vertical offset.

@Piinks
Copy link
Contributor

Piinks commented Aug 29, 2023

Hey @bleroux, just checking in from triage, what's the status of this PR?

@Renzo-Olivares
Copy link
Contributor

Renzo-Olivares commented Aug 29, 2023

Hi @bleroux I apologize for missing this. Thank you for the clear and in depth explanation of the issue.

Screen.Recording.2023-08-29.at.4.22.13.PM.mov

From my observation on the web you can select between above and below the lineHeight set. It looks like it will always select the first word of the paragraph in this case. The current implementation of handleSelectWord in MultiSelectableSelectionContainerDelegate does not allow for this because it checks if the position is within the text rect. I think for now we can adjust the gesture vertical offset and fix the assertion crash https://github.com/flutter/flutter/pull/129627#issuecomment-1609958996, but we should also add a TODO and create an issue for this so we can get this behavior right in the future.

@bleroux bleroux force-pushed the update_selectableregion_test_for_M3 branch from c30c770 to e9eaa49 Compare August 30, 2023 08:29
@bleroux bleroux marked this pull request as ready for review August 30, 2023 08:30
@bleroux
Copy link
Contributor Author

bleroux commented Aug 30, 2023

Hey @Renzo-Olivares!
I filed #133637 and I updated the PR:

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the change!

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 30, 2023
@auto-submit auto-submit bot merged commit 1fe2495 into flutter:master Aug 30, 2023
@bleroux bleroux deleted the update_selectableregion_test_for_M3 branch August 30, 2023 13:28
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 30, 2023
flutter/flutter@6c95737...1fe2495

2023-08-30 [email protected] Update SelectableRegion test for M3 (flutter/flutter#129627)
2023-08-30 [email protected] Remove cirrus tests from the flutter framework. (flutter/flutter#133575)
2023-08-30 [email protected] Roll Flutter Engine from 749e67a947bc to 69f04bdfe952 (2 revisions) (flutter/flutter#133621)
2023-08-30 [email protected] [flutter roll] Revert "Fix `Chip.shape`'s side is not used when provided in Material 3" (flutter/flutter#133615)
2023-08-30 [email protected] Roll Flutter Engine from 9f2cf5c99b0f to 749e67a947bc (2 revisions) (flutter/flutter#133618)
2023-08-30 [email protected] Roll Flutter Engine from c5854a6b3658 to 9f2cf5c99b0f (4 revisions) (flutter/flutter#133616)
2023-08-30 [email protected] No longer include `.packages` in created `.gitignore` files (flutter/flutter#133484)
2023-08-30 [email protected] Roll Flutter Engine from db3ecf8b2739 to c5854a6b3658 (1 revision) (flutter/flutter#133610)
2023-08-29 [email protected] Roll Flutter Engine from 1feb9302050c to db3ecf8b2739 (4 revisions) (flutter/flutter#133609)
2023-08-29 [email protected] Fix one notDisposed leak and mark another. (flutter/flutter#133595)
2023-08-29 [email protected] Roll Flutter Engine from 01a1579808b5 to 1feb9302050c (1 revision) (flutter/flutter#133604)
2023-08-29 [email protected] Upgrade packages. (flutter/flutter#133593)
2023-08-29 [email protected] Cover more tests with leak tracking. (flutter/flutter#133596)
2023-08-29 [email protected] Roll Flutter Engine from 73cc3fb451fd to 01a1579808b5 (3 revisions) (flutter/flutter#133591)
2023-08-29 [email protected] Added DropdownMenuEntry.labelWidget (flutter/flutter#133491)
2023-08-29 [email protected] Use a fake stopwatch to remove flakiness. (flutter/flutter#133229)
2023-08-29 [email protected] Roll Flutter Engine from d1e6eb080f08 to 73cc3fb451fd (3 revisions) (flutter/flutter#133580)
2023-08-29 [email protected] [web] Migrate remaining web-only API usages to `dart:ui_web` (flutter/flutter#132248)
2023-08-29 [email protected] Add doxygen doc generation. (flutter/flutter#131356)
2023-08-29 [email protected] Roll Flutter Engine from 50bd80773287 to d1e6eb080f08 (2 revisions) (flutter/flutter#133570)
2023-08-29 [email protected] ShortcutManager should dispatch creation in constructor. (flutter/flutter#133487)
2023-08-29 [email protected] Add FAB Additional Color Mappings example (flutter/flutter#133453)
2023-08-29 [email protected] Roll Flutter Engine from 65438c7bb46a to 50bd80773287 (1 revision) (flutter/flutter#133565)
2023-08-29 [email protected] Roll Packages from 383bffa to d7d3150 (13 revisions) (flutter/flutter#133564)

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 [email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

selectable_region_test.dart failure when switching to M3

4 participants