From 7a8b7952e0991250b053ef8fb3f2323ca2701190 Mon Sep 17 00:00:00 2001 From: Alan Mantoux Date: Thu, 28 Dec 2023 19:44:20 +0100 Subject: [PATCH] Handle dragging the base handle that makes it the extent on Apple platforms --- .../fleather/lib/src/widgets/text_selection.dart | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/fleather/lib/src/widgets/text_selection.dart b/packages/fleather/lib/src/widgets/text_selection.dart index a124d158..e71bb7a8 100644 --- a/packages/fleather/lib/src/widgets/text_selection.dart +++ b/packages/fleather/lib/src/widgets/text_selection.dart @@ -202,6 +202,10 @@ class EditorTextSelectionOverlay { } void _updateSelectionOverlay() { + // Swap occurs when dragging start handle on Apple systems + final isAppleSwapped = + selectionDelegate.textEditingValue.selection.baseOffset > + selectionDelegate.textEditingValue.selection.extentOffset; _selectionOverlay // Update selection handle metrics. ..startHandleType = _chooseType( @@ -210,16 +214,18 @@ class EditorTextSelectionOverlay { TextSelectionHandleType.right, ) // TODO: use _getStartGlyphHeight when adapted from flutter - ..lineHeightAtStart = renderObject.preferredLineHeight( - selectionDelegate.textEditingValue.selection.base) + ..lineHeightAtStart = renderObject.preferredLineHeight(isAppleSwapped + ? selectionDelegate.textEditingValue.selection.extent + : selectionDelegate.textEditingValue.selection.base) ..endHandleType = _chooseType( renderObject.textDirection, TextSelectionHandleType.right, TextSelectionHandleType.left, ) // TODO: use _getEndGlyphHeight when adapted from flutter - ..lineHeightAtEnd = renderObject.preferredLineHeight( - selectionDelegate.textEditingValue.selection.extent) + ..lineHeightAtEnd = renderObject.preferredLineHeight(isAppleSwapped + ? selectionDelegate.textEditingValue.selection.base + : selectionDelegate.textEditingValue.selection.extent) // Update selection toolbar metrics. ..selectionEndpoints = renderObject.getEndpointsForSelection(_selection) ..toolbarLocation = renderObject.lastSecondaryTapDownPosition;