Unverified Commit 413c8a0b authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Do not replace text with semantics labels in selectable text widgets (#77859)

parent 2530f4c5
...@@ -25,7 +25,7 @@ class _TextSpanEditingController extends TextEditingController { ...@@ -25,7 +25,7 @@ class _TextSpanEditingController extends TextEditingController {
_TextSpanEditingController({required TextSpan textSpan}): _TextSpanEditingController({required TextSpan textSpan}):
assert(textSpan != null), assert(textSpan != null),
_textSpan = textSpan, _textSpan = textSpan,
super(text: textSpan.toPlainText()); super(text: textSpan.toPlainText(includeSemanticsLabels: false));
final TextSpan _textSpan; final TextSpan _textSpan;
......
...@@ -1835,7 +1835,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -1835,7 +1835,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
// Returns the obscured text when [obscureText] is true. See // Returns the obscured text when [obscureText] is true. See
// [obscureText] and [obscuringCharacter]. // [obscureText] and [obscuringCharacter].
String get _plainText { String get _plainText {
_cachedPlainText ??= _textPainter.text!.toPlainText(); _cachedPlainText ??= _textPainter.text!.toPlainText(includeSemanticsLabels: false);
return _cachedPlainText!; return _cachedPlainText!;
} }
...@@ -2993,8 +2993,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -2993,8 +2993,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
return TextSelection(baseOffset: 0, extentOffset: _plainText.length); return TextSelection(baseOffset: 0, extentOffset: _plainText.length);
// If the word is a space, on iOS try to select the previous word instead. // 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. // On Android try to select the previous word instead only if the text is read only.
} else if (text?.toPlainText() != null } else if (_isWhitespace(_plainText.codeUnitAt(position.offset))
&& _isWhitespace(text!.toPlainText().codeUnitAt(position.offset))
&& position.offset > 0) { && position.offset > 0) {
assert(defaultTargetPlatform != null); assert(defaultTargetPlatform != null);
final TextRange? previousWord = _getPreviousWord(word.start); final TextRange? previousWord = _getPreviousWord(word.start);
......
...@@ -2866,6 +2866,37 @@ void main() { ...@@ -2866,6 +2866,37 @@ void main() {
expect(find.byType(CupertinoButton), findsNWidgets(1)); expect(find.byType(CupertinoButton), findsNWidgets(1));
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, 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( testWidgets(
'tap after a double tap select is not affected (iOS)', 'tap after a double tap select is not affected (iOS)',
(WidgetTester tester) async { (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment