Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Nov 5, 2021

When selection moves on desktop, the field will now scroll to view the scroll extent, like it already does on mobile.

edge_mac_2

TODO:

  • Make sure horizontal edge scrolling works.
  • Make sure this works on Windows.
  • Tests.

Fixes #32344
Fixes #59141

@justinmc justinmc self-assigned this Nov 5, 2021
@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 Nov 5, 2021
@google-cla google-cla bot added the cla: yes label Nov 5, 2021
@justinmc justinmc force-pushed the edge-scrolling-desktop branch from b47b649 to e309a02 Compare November 8, 2021 20:50
@justinmc
Copy link
Contributor Author

justinmc commented Nov 9, 2021

@mdebbar Is this old TODO of yours actually fixed?

// TODO(mdebbar): Support dragging in any direction (for multiline text).
// https://github.com/flutter/flutter/issues/28676

I ran into a strange problem where vertical mouse dragging wasn't being detected properly in a test. I'm wondering if there's anything unimplemented there that could be causing it, or if that TODO should be removed.

@mdebbar
Copy link
Contributor

mdebbar commented Nov 9, 2021

@justinmc if you look at that code, it's only using a HorizontalDragGestureRecognizer which doesn't detect vertical dragging. At that time, vertical dragging was used for scrolling (even on web, because there was no scroll bars yet). But now I think that's not the case anymore. Maybe we should use PanGestureRecognizer?

@justinmc
Copy link
Contributor Author

Sounds good, thanks for the info. I'll make a quick attempt at using PanGestureRecognizer and see if that fixes the strange missing vertical drag component that I saw in the test. If it seems complicated, I'll save it for another PR.

@justinmc justinmc force-pushed the edge-scrolling-desktop branch from 0515541 to 904d164 Compare November 10, 2021 19:27
@justinmc justinmc force-pushed the edge-scrolling-desktop branch from aeb96e8 to ccad131 Compare November 10, 2021 21:55
DragStartDetails? _lastDragStartDetails;
DragUpdateDetails? _lastDragUpdateDetails;
Timer? _dragUpdateThrottleTimer;
bool _isMouseDragging = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

HorizontalDragGestureRecognizer allows you to specify the type of pointer to accept, but now that we've switched to PanGestureRecognizer, which doesn't support that, we have to manually make sure we only listen to mouse drags.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong Nov 11, 2021

Choose a reason for hiding this comment

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

Would it be possible to add that to the existing PanGestureRecognizer or use a private subclass of PanGestureRecognizer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea, looks like it's actually only a 2 line change to add it to PanGesureRecognizer because the super class already supports it.

@justinmc justinmc marked this pull request as ready for review November 11, 2021 01:07
@justinmc
Copy link
Contributor Author

@mdebbar Switching to PanGestureRecognizer worked without too much tweaking, and it fixed my test! I've replaced it here in this PR and removed your TODO.

switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
if (cause == SelectionChangedCause.longPress
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious what does a long-press do on iOS and macOS? Is it the force press floating cursor that makes them different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup this handles the thing where you force press and then drag the cursor.

PointerDeviceKind? kind,
}) : super(
debugOwner: debugOwner,
kind: kind,
Copy link
Contributor

Choose a reason for hiding this comment

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

kind is deprecated I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I missed that, thanks. I'll do the same thing but with supportedDevices as the deprecation message suggests.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong 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 should also close #28676 (the TODO issue) right?

@justinmc
Copy link
Contributor Author

@LongCatIsLooong That one is already closed, but I guess the TODO was missed.

@fluttergithubbot fluttergithubbot merged commit 297a7c7 into flutter:master Nov 16, 2021
@justinmc justinmc deleted the edge-scrolling-desktop branch November 16, 2021 23:05
@justinmc
Copy link
Contributor Author

Adding the cherry pick tag after discussing with @mariamhas, if we're still doing cherry picks for 2.8. Shouldn't be a high risk of regressions.

WizzXu pushed a commit to WizzXu/flutter that referenced this pull request Nov 19, 2021
@devoncarew
Copy link
Contributor

@justinmc and @HansMuller - when was this regression introduced? What's the impact if we don't take it for this hotfix? We should carefully weigh taking it now (the week right before the release) w/ delaying until a batch of fixes after the release.

@justinmc
Copy link
Contributor Author

I'm ok with skipping this. The behavior without it is fairly bad, but it's actually not a regression. Also there were previously a few goldens issues with this. Probably best to let it be released normally if @mariamhas is alright with that.

@mariamhas
Copy link
Contributor

mariamhas commented Nov 30, 2021 via email

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.

Can't select text with mouse once it's longer than the text field Implement edge scrolling for text selection in Text/TextField

6 participants