Skip to content

Conversation

@Rexios80
Copy link
Member

Replaces #121112 since that one turned into a mess of changes we don't want


Right now, copying text in a SelectionArea copies it with no separation. Since SelectionArea is very useful with vertical lists of Text widgets this is not ideal. This PR adds a separator field to SelectionArea so that developers can add separators such as newlines between selected Text widgets.

#104548

I added a new test for this

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 f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels May 15, 2023
@HansMuller HansMuller added a: text input Entering text in a text field or keyboard related problems f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs labels May 19, 2023
@HansMuller HansMuller requested review from chunhtai and justinmc May 19, 2023 17:37
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.

Thanks for reopening this. The approach looks good, but I'll defer to @chunhtai.

/// Called when the selected content changes.
final ValueChanged<SelectedContent?>? onSelectionChanged;

/// The separator to use when concatenating the selected text.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would explain the default value of empty string here, too, and then say that you might want to use '\n' instead.

Actually, maybe we should default to newline?

Choose a reason for hiding this comment

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

@justinmc I don't think we should default to newline as that could introduce a breaking change to apps already using it and expecting no separator.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any existing apps that are expecting no separator, or would they consider that a bug? I would guess that most expect as newline separator, but it's true I'm just guessing. If you @dsyrstad have an app that expects no separator then that's pretty strong evidence we should keep that default.

Choose a reason for hiding this comment

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

@justinmc I don't have an app which expects no separator, but I was working on an e2e test that was going to check what was copied from the clipboard (which is how I ran into this issue). If there are existing e2e tests out there expecting it as it is, I'd guess they'd break. Also, it may be that users of apps historically expect it in a certain format, so you might break the users. I'm of the opinion to do the least harm possible. If an app wants a separator, it can configure it.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, thanks for sharing your context here! I'm happy either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the doc comment. Let me know if you have any thoughts.

@github-actions github-actions bot removed a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels May 24, 2023
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.

Thanks for the fixes! LGTM.

CC @chunhtai for review.

@justinmc
Copy link
Contributor

@Rexios80 Can you push a merge commit to fix the Google tests?

@Rexios80
Copy link
Member Author

Rexios80 commented Jun 5, 2023

@justinmc Is there anything else you need from me on this?

@justinmc
Copy link
Contributor

justinmc commented Jun 5, 2023

No, looks like the tests are green. I'll find a secondary reviewer.

@override
Widget build(BuildContext context) {
assert(debugCheckHasOverlay(context));
final SelectionRegistrar? registrar = SelectionContainer.maybeOf(context);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be stacking selectable regions. Is this for setting different separate for the subtree? if so, can you create a new named SelectionContainer constructor that takes in a separator and create a _SelectableRegionContainerDelegate with that separate in its state?

for example something like SelectionContainer.options(separator: '\n');

Copy link
Member Author

Choose a reason for hiding this comment

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

How does making a different constructor change anything?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because SelectableRegion doesn't mean to nest, and the SelectionContainer does.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what to do here. If the SelectableRegions don't share a registrar how will they get separated when copied?

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 7, 2023
@justinmc
Copy link
Contributor

@Rexios80 What do you think of @YeungKC's idea to add an onCopy function instead of separators?

@Rexios80
Copy link
Member Author

I like that idea, but someone else will probably have to implement it if we want it done any time soon. I got busy with other work.

@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Hixie
Copy link
Contributor

Hixie commented Oct 31, 2023

@Rexios80 thanks so much for your contributions here, I've added a link to this PR to the issue so hopefully your work will not be in vain! I'm going to close this for now since you are no longer working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants