-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add support for separators in text copied from SelectableRegion
#126835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for separators in text copied from SelectableRegion
#126835
Conversation
justinmc
left a comment
There was a problem hiding this 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…-2' into feature/selection-area-separator-2
justinmc
left a comment
There was a problem hiding this 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.
|
@Rexios80 Can you push a merge commit to fix the Google tests? |
|
@justinmc Is there anything else you need from me on this? |
|
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); |
There was a problem hiding this comment.
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');
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
|
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. |
|
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 Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
@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. |
Replaces #121112 since that one turned into a mess of changes we don't want
Right now, copying text in a
SelectionAreacopies it with no separation. SinceSelectionAreais very useful with vertical lists ofTextwidgets this is not ideal. This PR adds aseparatorfield toSelectionAreaso that developers can add separators such as newlines between selectedTextwidgets.#104548
I added a new test for this
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.