Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Dec 7, 2023

Description

This PR adds custom system-wide text selection toolbar buttons on Android.
This is a WIP until #139479 is merged (potential conflicts).

Related Issue

Fixes #139361

Tests

Adds 5 tests.

@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. f: material design flutter/packages/flutter/material repository. labels Dec 7, 2023
@bleroux bleroux force-pushed the add_android_activities_text_actions_to_selection_toolbar branch from 9cb842d to 19715e3 Compare December 11, 2023 06:33
@bleroux bleroux marked this pull request as ready for review December 11, 2023 07:13
@bleroux bleroux force-pushed the add_android_activities_text_actions_to_selection_toolbar branch from 19715e3 to 63cce19 Compare December 11, 2023 07:13
@bleroux bleroux force-pushed the add_android_activities_text_actions_to_selection_toolbar branch 2 times, most recently from 4e0f662 to 070dffb Compare December 13, 2023 14:55
@bleroux bleroux force-pushed the add_android_activities_text_actions_to_selection_toolbar branch 2 times, most recently from 70c51ad to 23b4c5b Compare December 15, 2023 14:16
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also not build the system wide buttons if the text selection is invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check was inspired by the implementation of accessors such as cutEnabled, copyEnabled, etc. See

bool get copyEnabled {
if (widget.selectionControls is! TextSelectionHandleControls) {
return widget.toolbarOptions.copy && !widget.obscureText;
}
return !widget.obscureText
&& !textEditingValue.selection.isCollapsed;

Those accessors are called in EditablTestState.contextMenuButtonItems just before the call to _textProcessingActionButtonItems I added. Because this is meant to build the text selection toolbar, it would make sense that a check to TextSelection.isValid is done somewhere before.

I did not spot an obvious place where such a check is done so I have updated the PR to add this check on the line you commented.

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares Dec 15, 2023

Choose a reason for hiding this comment

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

For my understanding what does an app developer expect when the system wide button is used on static text/readOnly? And in what cases would processedText be null?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the buttons are expected to do nothing on static text, do they still show up when used on static text despite that?

Copy link
Contributor Author

@bleroux bleroux Dec 16, 2023

Choose a reason for hiding this comment

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

They are two types of activities registered to Intent.ACTION_PROCESS_TEXT:

  • some will use the selected text (selectedText variable in this code) to open their UI and will display a result (for instance, on my phone I have one activity that will read the text loudly, I also have Google Translate and Deepl that will show the translation using their own panels). Such activities does not return a result (processedText will be null in this case).
  • some will use the selected text to return a modified version (on my phone I have an app called 'Encrypt Text' that does that (it opens an UI where I can ask to see the encrypted text and a button to replace the current selection with this encrypted text). Such activities returns a result (processedText won't be null in this case and we use it to replace the current selection).

I have upated the PR with a comment to explain that is expected that some activities does not return a modified text.

@bleroux bleroux force-pushed the add_android_activities_text_actions_to_selection_toolbar branch from 23b4c5b to 4af1bd8 Compare December 18, 2023 14:40
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 30, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 30, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 31, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 2, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2024
auto-submit bot pushed a commit that referenced this pull request Jan 9, 2024
…electableRegion (#141103)

## Description

This PR adds custom system-wide text selection toolbar buttons on Android for `SelectableRegion` and `SelectionArea`.

#139738 adds those buttons for `EditableText` (which is used by `TextField` and `SelectableText` but not by `SelectionArea`).

## Related Issue

Step 5 for #139361

## Tests

Adds 2 tests.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 16, 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 f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Respect custom system-wide text selection toolbar buttons

2 participants