Skip to content

Commit

Permalink
fix drag selection extension (does not start at tap location if you a…
Browse files Browse the repository at this point in the history
…re dragging quickly) (#2170)

Co-authored-by: Jesse Ezell <[email protected]>
  • Loading branch information
jezell and timu-jesse-ezell authored Aug 31, 2024
1 parent f60ac03 commit 0b55bd8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/src/editor/widgets/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ class EditorTextSelectionGestureDetectorBuilder {
assert(renderEditor?.selection.baseOffset != null);

final tappedPosition = renderEditor!.getPositionForOffset(offset);
final selection = renderEditor!.selection;
final selection = switch (cause) {
SelectionChangedCause.drag => _dragStartSelection!,
_ => renderEditor!.selection
};

final nextSelection = selection.copyWith(
extentOffset: tappedPosition.offset,
);
Expand Down Expand Up @@ -691,7 +695,7 @@ class EditorTextSelectionGestureDetectorBuilder {
switch (details.kind) {
case PointerDeviceKind.mouse:
case PointerDeviceKind.trackpad:
renderEditor?.selectPositionAt(
_dragStartSelection = renderEditor?.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.drag,
);
Expand All @@ -704,7 +708,7 @@ class EditorTextSelectionGestureDetectorBuilder {
assert(_dragBeganOnPreviousSelection != null);
if (renderEditor?.hasFocus == true &&
_dragBeganOnPreviousSelection!) {
renderEditor?.selectPositionAt(
_dragStartSelection = renderEditor?.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.drag,
);
Expand All @@ -717,7 +721,7 @@ class EditorTextSelectionGestureDetectorBuilder {
switch (details.kind) {
case PointerDeviceKind.mouse:
case PointerDeviceKind.trackpad:
renderEditor?.selectPositionAt(
_dragStartSelection = renderEditor?.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.drag,
);
Expand All @@ -728,7 +732,7 @@ class EditorTextSelectionGestureDetectorBuilder {
// For Android, Fucshia, and iOS platforms, a touch drag
// does not initiate unless the editable has focus.
if (renderEditor?.hasFocus == true) {
renderEditor?.selectPositionAt(
_dragStartSelection = renderEditor?.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.drag,
);
Expand All @@ -739,7 +743,7 @@ class EditorTextSelectionGestureDetectorBuilder {
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
renderEditor?.selectPositionAt(
_dragStartSelection = renderEditor?.selectPositionAt(
from: details.globalPosition,
cause: SelectionChangedCause.drag,
);
Expand Down

0 comments on commit 0b55bd8

Please sign in to comment.