Skip to content

Conversation

@chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Feb 22, 2022

The main motivation of this change is that other widget no longer need to create ClipboardStatusNotifier to use SelectionOverlay if they don't need paste functionality. Furthermore, it should not be TextSelectionOverlay's job to refresh the ClipboardStatus to notify itself, it should be whoever handles cut/paste to refresh the clipboard status. It also allows more flexibility if one does not rely on system clipboard.

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.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Feb 22, 2022
void handleCut(TextSelectionDelegate delegate, ClipboardStatusNotifier? clipboardStatus) {
void handleCut(TextSelectionDelegate delegate) {
delegate.cutSelection(SelectionChangedCause.toolbar);
clipboardStatus?.update();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be the delegate's job to call update on clipboardStatus since it is the owner. There may also be use case that cutSelection does not write thing into clipboard due to other short-circuited condition

void handleCopy(TextSelectionDelegate delegate, ClipboardStatusNotifier? clipboardStatus) {
void handleCopy(TextSelectionDelegate delegate) {
delegate.copySelection(SelectionChangedCause.toolbar);
clipboardStatus?.update();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here


bool _disposed = false;
/// True if this instance has been disposed.
bool get disposed => _disposed;
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 is used by the listeners to decide whether they should call removeListener when they are disposed

This is no longer needed because removeListener is allowed to be called after it is disposed now

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy to see this going away 👍

@chunhtai chunhtai requested a review from justinmc February 23, 2022 00:53
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 👍

This looks cleaner and I agree we shouldn't have the selection toolbar depend on the clipboard status unless it actually uses "paste".

Widget build(BuildContext context) {
// Don't render the menu until the state of the clipboard is known.
if (widget.handlePaste != null && _clipboardStatus!.value == ClipboardStatus.unknown) {
if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if clipboardStatus is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if it is null it will skip this if condition and still build the toolbar. We only want to skip if we need to build the paste button( has handlePaste and has _clipboardStatus) and the status is unknown

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that makes sense 👍


bool _disposed = false;
/// True if this instance has been disposed.
bool get disposed => _disposed;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy to see this going away 👍

@chunhtai chunhtai merged commit c74a646 into flutter:master Feb 23, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 23, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 23, 2022
chunhtai added a commit to chunhtai/flutter that referenced this pull request Mar 1, 2022
chunhtai added a commit that referenced this pull request Mar 1, 2022
chunhtai added a commit to chunhtai/flutter that referenced this pull request Mar 1, 2022
renyou pushed a commit to renyou/flutter that referenced this pull request Mar 2, 2022
renyou added a commit that referenced this pull request Mar 2, 2022
This reverts commit c74a646.

Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
renyou added a commit that referenced this pull request Mar 2, 2022
* Revert "Clean up ClipboardStatusNotifier (#98951)" (#99361)

This reverts commit c74a646.

* Revert "Draggable can be accepted when the data is null" (#99419)

Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Kate Lovett <katelovett@google.com>
renyou added a commit that referenced this pull request Mar 3, 2022
* Revert "Clean up ClipboardStatusNotifier (#98951)" (#99361)

This reverts commit c74a646.

* Revert "Draggable can be accepted when the data is null" (#99419)

* Cherrypick engine to 32395e4ab410df3b7d05b0f90d2601c5c7d27024

Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Kate Lovett <katelovett@google.com>
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Mar 8, 2022
* Clean up ClipboardStatusNotifier

* fix

* fix test

* more refactaaaaagit add .
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Mar 8, 2022
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 f: cupertino flutter/packages/flutter/cupertino repository 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.

2 participants