Skip to content

Conversation

@Renzo-Olivares
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares commented Aug 21, 2024

Fixes #153003

Pressing backspace on CJK keyboards to delete text may trigger a key event which in turns triggers the DeleteTextIntent. This is different than English keyboards where the updated TextEditingValue from the TextInputPlugin will come through updateEditingValue which allows us to hit the codepath that hides the text selection toolbar.

if (value.text != _value.text) {
// Hide the toolbar if the text was changed, but only hide the toolbar
// overlay; the selection handle's visibility will be handled
// by `_handleSelectionChanged`. https://github.com/flutter/flutter/issues/108673
hideToolbar(false);
}
Because CJK keyboards may not hit this codepath, when the text is long and editable text tries to bring the new selection into view by scrolling, this triggers the hide context menu scroll listener in a weird state
final Rect selectionBounds = _value.selection.isCollapsed || selectionBoxes.isEmpty
? renderEditable.getLocalRectForCaret(_value.selection.extent)
: selectionBoxes
.map((TextBox box) => box.toRect())
.reduce((Rect result, Rect rect) => result.expandToInclude(rect));
causing an exception to be thrown.

This PR tries to work around the issue above by hiding the toolbar when a DeleteTextIntent is received.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Aug 21, 2024
@Renzo-Olivares Renzo-Olivares changed the title Fix: Deleting text in EditableText while in CupertinoPageRoute throws exception Fix: Deleting text in EditableText while in CupertinoPageRoute throws exception Aug 21, 2024
@Renzo-Olivares Renzo-Olivares changed the title Fix: Deleting text in EditableText while in CupertinoPageRoute throws exception Fix: Deleting text in EditableText while in CupertinoPageRoute throws exception Aug 21, 2024
@Renzo-Olivares Renzo-Olivares changed the title Fix: Deleting text in EditableText while in CupertinoPageRoute throws exception Fix: Deleting text in EditableText with CJK keyboard while in CupertinoPageRoute throws exception Aug 21, 2024
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Is this for the software keyboard? What a roundabout bug. Thanks for fixing.

await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(state.selectionOverlay, isNotNull);
expect(state.selectionOverlay!.toolbarIsVisible, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe also expect that the text has changed so that the selected word is gone? If you think it's valuable.

@Renzo-Olivares
Copy link
Contributor Author

Yeah this was for the software keyboard. For some reason this bug does not affect MaterialPageRoute, but this patch achieves the correct behavior I see on native Android and iOS (the toolbar should be hidden when text is deleted), and fixes the crash.

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 21, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 21, 2024

auto label is removed for flutter/flutter/153822, due to - The status or check suite Linux web_long_running_tests_5_5 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 21, 2024
@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 21, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 21, 2024

auto label is removed for flutter/flutter/153822, due to - The status or check suite Linux web_long_running_tests_5_5 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 21, 2024
@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 21, 2024
@auto-submit auto-submit bot merged commit f6054ae into flutter:master Aug 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 31, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 31, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2024
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…rtinoPageRoute` throws exception (flutter#153822)

Fixes flutter#153003

Pressing backspace on CJK keyboards to delete text may trigger a key event which in turns triggers the `DeleteTextIntent`. This is different than English keyboards where the updated `TextEditingValue` from the `TextInputPlugin` will come through `updateEditingValue` which allows us to hit the codepath that hides the text selection toolbar. https://github.com/flutter/flutter/blob/23883b13d4919bed4f572e78cb60c016bb3b872f/packages/flutter/lib/src/widgets/editable_text.dart#L3245-L3250 Because CJK keyboards may not hit this codepath, when the text is long and editable text tries to bring the new selection into view by scrolling, this triggers the hide context menu scroll listener in a weird state https://github.com/flutter/flutter/blob/23883b13d4919bed4f572e78cb60c016bb3b872f/packages/flutter/lib/src/widgets/editable_text.dart#L3865-L3869 causing an exception to be thrown.

This PR tries to work around the issue above by hiding the toolbar when a `DeleteTextIntent` is received.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems 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.

TextFormField may throw Exception when deleting text from field with CJK keyboard in a route pushed using CupertinoPageRoute on Android

2 participants