From e8accfe2ab41bca62868dfcb7820f41b88c87c5b Mon Sep 17 00:00:00 2001 From: Serhii Horbenko Date: Wed, 27 Mar 2024 13:14:30 +0200 Subject: [PATCH] Improve text selection when using drag handles --- lib/src/widgets/others/text_selection.dart | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/src/widgets/others/text_selection.dart b/lib/src/widgets/others/text_selection.dart index ab290819..0c6d3e3f 100644 --- a/lib/src/widgets/others/text_selection.dart +++ b/lib/src/widgets/others/text_selection.dart @@ -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;