mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Do not replace text with semantics labels in selectable text widgets (#77859)
This commit is contained in:
parent
2530f4c5eb
commit
413c8a0b7b
@ -25,7 +25,7 @@ class _TextSpanEditingController extends TextEditingController {
|
||||
_TextSpanEditingController({required TextSpan textSpan}):
|
||||
assert(textSpan != null),
|
||||
_textSpan = textSpan,
|
||||
super(text: textSpan.toPlainText());
|
||||
super(text: textSpan.toPlainText(includeSemanticsLabels: false));
|
||||
|
||||
final TextSpan _textSpan;
|
||||
|
||||
|
||||
@ -1835,7 +1835,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
||||
// Returns the obscured text when [obscureText] is true. See
|
||||
// [obscureText] and [obscuringCharacter].
|
||||
String get _plainText {
|
||||
_cachedPlainText ??= _textPainter.text!.toPlainText();
|
||||
_cachedPlainText ??= _textPainter.text!.toPlainText(includeSemanticsLabels: false);
|
||||
return _cachedPlainText!;
|
||||
}
|
||||
|
||||
@ -2993,8 +2993,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
||||
return TextSelection(baseOffset: 0, extentOffset: _plainText.length);
|
||||
// If the word is a space, on iOS try to select the previous word instead.
|
||||
// On Android try to select the previous word instead only if the text is read only.
|
||||
} else if (text?.toPlainText() != null
|
||||
&& _isWhitespace(text!.toPlainText().codeUnitAt(position.offset))
|
||||
} else if (_isWhitespace(_plainText.codeUnitAt(position.offset))
|
||||
&& position.offset > 0) {
|
||||
assert(defaultTargetPlatform != null);
|
||||
final TextRange? previousWord = _getPreviousWord(word.start);
|
||||
|
||||
@ -2866,6 +2866,37 @@ void main() {
|
||||
expect(find.byType(CupertinoButton), findsNWidgets(1));
|
||||
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
|
||||
|
||||
testWidgets(
|
||||
'double tap selects word with semantics label',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: SelectableText.rich(
|
||||
TextSpan(text: 'Atwater Peel Sherbrooke Bonaventure', semanticsLabel: ''),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Offset selectableTextStart = tester.getTopLeft(find.byType(SelectableText));
|
||||
|
||||
await tester.tapAt(selectableTextStart + const Offset(220.0, 5.0));
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await tester.tapAt(selectableTextStart + const Offset(220.0, 5.0));
|
||||
await tester.pump();
|
||||
|
||||
final EditableText editableTextWidget = tester.widget(find.byType(EditableText).first);
|
||||
final TextEditingController controller = editableTextWidget.controller;
|
||||
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection(baseOffset: 13, extentOffset: 23),
|
||||
);
|
||||
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
|
||||
|
||||
testWidgets(
|
||||
'tap after a double tap select is not affected (iOS)',
|
||||
(WidgetTester tester) async {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user