Skip to content

Commit

Permalink
Improve text selection when using drag handles
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Horbenko committed Mar 27, 2024
1 parent 0646495 commit e8accfe
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/src/widgets/others/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,24 @@ class _TextSelectionHandleOverlayState

void _handleDragUpdate(DragUpdateDetails details) {
_dragPosition += details.delta;
final position =
widget.renderObject.getPositionForOffset(details.globalPosition);
if (widget.selection.isCollapsed) {
final position = widget.renderObject.getPositionForOffset(
details.globalPosition,
);
widget.onSelectionHandleChanged(TextSelection.fromPosition(position));
return;
}

final textPosition = switch (widget.position) {
_TextSelectionHandlePosition.start => widget.selection.base,
_TextSelectionHandlePosition.end => widget.selection.extent,
};
final lineHeight = widget.renderObject.preferredLineHeight(textPosition);
final position = widget.renderObject.getPositionForOffset(
details.globalPosition.translate(0, switch (widget.position) {
_TextSelectionHandlePosition.start => lineHeight,
_TextSelectionHandlePosition.end => -lineHeight,
}),
);
final isNormalized =
widget.selection.extentOffset >= widget.selection.baseOffset;
TextSelection newSelection;
Expand Down

0 comments on commit e8accfe

Please sign in to comment.