-
Notifications
You must be signed in to change notification settings - Fork 29.2k
Supports global selection for all devices #95226
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
Conversation
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.
Haven't reviewed it all, just some comments from an initial read-through.
|
||
/// Called when the selectables this widget collected has changed. | ||
/// | ||
/// Use this method to extract the collected selectables in the subtree. |
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.
document that the selectables are given in screen order in the list?
|
||
DragSelectionStartEvent? _currentDragStart; | ||
|
||
/// Updates the selectables this updater manages. |
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.
Document that it expects the selectables in screen order (I think?)
/// Gets the list selectables this updater is responsible for updating. | ||
/// | ||
/// The subclasses is responsible for updating the selection when the | ||
/// selectables in the list has changed. |
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.
document expected order?
} | ||
|
||
/// Copies the selected contents of all the selectables. | ||
Object? copy() { |
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.
Should this be typed String?
? Seems to be the only possible return type?
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.
It may not be the case if we support multimedia, but i guess we can change that later?
|
||
/// Initialize the selection of the selectable children. | ||
/// | ||
/// The goal is to find which selectable child the selection starts on |
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.
missing .
This looks pretty interesting. It's nice to see that we can do this without adding things to RenderObject. What wasn't clear to me from my initial read-through is why we need |
late final SelectionResult result; | ||
if (event is DragSelectionEvent) { | ||
if (event is DragSelectionStartEvent) { | ||
_dragSelectionStartInGlobalCoordinate = event.offset; |
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.
Wouldn't we want to hold on to the start point in local coordinates und use that for the calculations in _updateDragSelection?
I am thinking about a scenario where you start the selection with a pointer down in a large body of text and while the pointer is down you scroll a surrounding scrollable. I think that scroll needs to extend the selection and the selection needs to start at the letter that the pointer touched when it cam down first. Due to the scroll, that letter will have moved in the global coordinate system, though.
/// should start before all of its children. Returns [SelectionResult.next] | ||
/// if the selection should start after all of its children. | ||
SelectionResult _initSelection(DragSelectionUpdateEvent event) { | ||
for (int index = 0; index < selectables.length; index += 1){ |
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.
nit: space before {
The biggest concern is select to scroll. Imagine a container with 3 child [A, B, C]. If B is scrollable and the drag selection goes to C, IMO we can't send update event to C until B finishes scrolling. We can also makes B returns some kind of flag to tell the container not to proceed and get rid of SelectionResult, but I think the current implementation is more systematic since there maybe more cases where selectable itself has opinion on the selection order. The other concern is keyboard selection. Imagine developer press shit+ down, how does the container know which selectable should be the new selection edge. With SelectionResult, the selectable itself can tell the container whether the shift down should reach the next selectable or not. |
Gold has detected about 1 new digest(s) on patchset 9. |
1387fce
to
bfab82c
Compare
Gold has detected about 2 new digest(s) on patchset 10. |
Gold has detected about 1 new digest(s) on patchset 11. |
Gold has detected about 1 new digest(s) on patchset 12. |
523b432
to
2cf4f8e
Compare
9425c57
to
01d68b6
Compare
please ignore the failing test for now, It is because I want to hide the selection specific logic in RenderParagraph by making a private subclass of it, and it failed the describe node test. I am thinking whether there is way around it or i will have to expose the API |
I will add more tests. This PR now supports both mouse selection and mobile selection. I figure i may need to tear up bunch of API in Selectable to separate both them into two PR, which may make it hard to comprehend. So I keep them in the same PR. |
also cc @jonahwilliams |
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.
Overall this LGTM after the last few comments are addressed.
examples/api/lib/material/selection_area/disable_partial_selection.dart
Outdated
Show resolved
Hide resolved
} | ||
} | ||
} | ||
if (widget.registrar != null) |
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.
What if it changes from non-null to null?
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.
It will be handled in didUpdateWidget
selection = const TextSelection.collapsed(offset: 1); | ||
break; | ||
} | ||
textEditingValue = TextEditingValue(text: '__', selection: selection); |
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.
Let's add some TODO comments here explaining that.
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.
LGTM
42e052a
to
577d624
Compare
From #95226 (review) @justinmc On macOS this not true for web (I don't know how Windows it handels): Screen.Recording.2022-05-25.at.00.46.29.mov(I used the flutter.dev website) |
@nilsreichardt Good catch. I think we're doing those gestures in another PR so we'll have to get this right there. |
@justinmc Yes, I also opened a few issue for the |
* Support global selection * addressing comments * add new test * Addressing review comments * update * addressing comments * addressing comments * Addressing comments * fix build
Support for mouse drag selection and mobile selection
#81839
design doc: http://flutter.dev/go/global-selection
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.