这是indexloc提供的服务,不要输入任何密码
Skip to content

Text is not selected when selection starts within line height but above or below the text #133637

@bleroux

Description

@bleroux

Is there an existing issue for this?

Steps to reproduce

Run the test provided in code sample section

Expected results

The test is successful.
When selecting a text, it should be valid to tap below or above the text if the tap position is within the full vertical height (line height).

Actual results

The test fails because the selection offset is in line height boundary but not on the text rect.

Using a golden image we can have a better understanding of what happens.

image

For more context, see #129627.

Code sample

Code sample
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets(
    'can select word when a selectables rect is completely inside of another selectables rect', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/127076.
    final UniqueKey outerText = UniqueKey();
    await tester.pumpWidget(
      MaterialApp(
        home: SelectableRegion(
          focusNode: FocusNode(),
          selectionControls: materialTextSelectionControls,
          child: Scaffold(
            body: Center(
              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.'),
                    ],
                ),
                key: outerText,
              ),
            ),
          ),
        ),
      ),
    );
    final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.descendant(of: find.byKey(outerText), matching: find.byType(RichText)).first);

    const Rect caret = Rect.fromLTWH(0.0, 0.0, 2.0, 20.0);
    final Offset localOffset = paragraph.getOffsetForCaret(const TextPosition(offset: 125), caret);
    final Offset gestureOffset = paragraph.localToGlobal(localOffset);

    // Right click to select word at position.
    final TestGesture gesture = await tester.startGesture(gestureOffset, kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton);
    addTearDown(gesture.removePointer);
    await tester.pump();
    await gesture.up();
    await tester.pump();
    // Should select "Hello".
    expect(paragraph.selections[0], const TextSelection(baseOffset: 124, extentOffset: 129));
  },
    variant: TargetPlatformVariant.only(TargetPlatform.macOS),
    skip: isBrowser, // https://github.com/flutter/flutter/issues/61020
  );
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following RangeError was thrown running a test:
RangeError (index): Invalid value: Valid value range is empty: 0

When the exception was thrown, this was the stack:
#0      List.[] (dart:core-patch/growable_array.dart:264:36)
#1      main.<anonymous closure> (file:///home/bruno/Nevercode/Investigation/investigationapp/test/useM3Migration/selectable_region/selectable_region_m3_failure_test.dart:53:32)
<asynchronous suspension>
#2      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:168:15)
<asynchronous suspension>
#3      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1012:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

The test description was:
  can select word when a selectables rect is completely inside of another selectables rect (variant:
  TargetPlatform.macOS)
════════════════════════════════════════════════════════════════════════════════════════════════════
Test failed. See exception logs above.
The test description was: can select word when a selectables rect is completely inside of another selectables rect (variant: TargetPlatform.macOS)```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[!] Flutter (Channel [user-branch], 3.14.0-6.0.pre.238, on Ubuntu 22.10 5.19.0-46-generic, locale fr_FR.UTF-8)
    ! Flutter version 3.14.0-6.0.pre.238 on channel [user-branch] at /home/bruno/Nevercode/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not the same as FLUTTER_GIT_URL
    • FLUTTER_GIT_URL = git@github.com:NevercodeHQ/flutter.git
    • Framework revision 56ea352cc0 (il y a 4 heures), 2023-08-29 21:00:10 -0700
    • Engine revision 69f04bdfe9
    • Dart version 3.2.0 (build 3.2.0-122.0.dev)
    • DevTools version 2.26.2
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /media/oldhome/Android/Sdk
    • Platform android-33-ext5, build-tools 33.0.2
    • ANDROID_HOME = /media/oldhome/Android/Sdk
    • Java binary at: /media/oldhome/Produits/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 15.0.7
    • cmake version 3.24.2
    • ninja version 1.11.0
    • pkg-config version 0.29.2

[✓] Android Studio (version 2021.3)
    • Android Studio at /media/oldhome/Produits/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version unknown)
    • VS Code at /snap/code/current
    • Flutter extension version 3.70.0
    ✗ Unable to determine VS Code version.

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.10 5.19.0-46-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 116.0.5845.110

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsf: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIsfound in release: 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions