diff --git a/packages/fleather/lib/src/rendering/editor.dart b/packages/fleather/lib/src/rendering/editor.dart index 78c9fd33..b7f8c99c 100644 --- a/packages/fleather/lib/src/rendering/editor.dart +++ b/packages/fleather/lib/src/rendering/editor.dart @@ -146,7 +146,6 @@ class RenderEditor extends RenderEditableContainerBox }) : _document = document, _hasFocus = hasFocus, _selection = selection, - _extendSelectionOrigin = selection, _startHandleLayerLink = startHandleLayerLink, _endHandleLayerLink = endHandleLayerLink, _cursorController = cursorController, @@ -209,18 +208,8 @@ class RenderEditor extends RenderEditableContainerBox if (_selection == value) return; _selection = value; markNeedsPaint(); - - if (!_shiftPressed && !_isDragging) { - // Only update extend selection origin if Shift key is not pressed and - // user is not dragging selection. - _extendSelectionOrigin = _selection; - } } - bool get _shiftPressed => - RawKeyboard.instance.keysPressed.contains(LogicalKeyboardKey.shiftLeft) || - RawKeyboard.instance.keysPressed.contains(LogicalKeyboardKey.shiftLeft); - /// The [LayerLink] of start selection handle. /// /// [RenderEditable] is responsible for calculating the [Offset] of this @@ -422,11 +411,6 @@ class RenderEditor extends RenderEditableContainerBox Offset? _lastTapDownPosition; - // Used on Desktop (mouse and keyboard enabled platforms) as base offset - // for extending selection, either with combination of `Shift` + Click or - // by dragging - TextSelection? _extendSelectionOrigin; - @override void handleSecondaryTapDown(TapDownDetails details) { _lastTapDownPosition = details.globalPosition; @@ -438,25 +422,6 @@ class RenderEditor extends RenderEditableContainerBox _lastTapDownPosition = details.globalPosition; } - bool _isDragging = false; - - void handleDragStart(TapDragStartDetails details) { - _isDragging = true; - - final newSelection = selectPositionAt( - from: details.globalPosition, - cause: SelectionChangedCause.drag, - ); - - if (newSelection == null) return; - // Make sure to remember the origin for extend selection. - _extendSelectionOrigin = newSelection; - } - - void handleDragEnd(TapDragEndDetails details) { - _isDragging = false; - } - /// Called when the selection changes. /// /// If this is null, then selection changes will be ignored. @@ -487,34 +452,6 @@ class RenderEditor extends RenderEditableContainerBox ); } - /// Extends current selection to the position closest to specified offset. - void extendSelection(Offset to, {required SelectionChangedCause cause}) { - /// The below logic does not exactly match the native version because - /// we do not allow swapping of base and extent positions. - assert(_extendSelectionOrigin != null); - final position = getPositionForOffset(to); - - if (position.offset < _extendSelectionOrigin!.baseOffset) { - _handleSelectionChange( - TextSelection( - baseOffset: position.offset, - extentOffset: _extendSelectionOrigin!.extentOffset, - affinity: selection.affinity, - ), - cause, - ); - } else if (position.offset > _extendSelectionOrigin!.extentOffset) { - _handleSelectionChange( - TextSelection( - baseOffset: _extendSelectionOrigin!.baseOffset, - extentOffset: position.offset, - affinity: selection.affinity, - ), - cause, - ); - } - } - @override void selectWordEdge({required SelectionChangedCause cause}) { // _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); diff --git a/packages/fleather/lib/src/widgets/text_selection.dart b/packages/fleather/lib/src/widgets/text_selection.dart index 90b467a5..5c60d000 100644 --- a/packages/fleather/lib/src/widgets/text_selection.dart +++ b/packages/fleather/lib/src/widgets/text_selection.dart @@ -526,17 +526,11 @@ class _TextSelectionHandleOverlayState extends State /// Delegate interface for the [EditorTextSelectionGestureDetectorBuilder]. /// /// The interface is usually implemented by textfield implementations wrapping -/// [EditableText], that use a [EditorTextSelectionGestureDetectorBuilder] to build a -/// [EditorTextSelectionGestureDetector] for their [editor]. The delegate provides +/// [RawEditor], that use a [EditorTextSelectionGestureDetectorBuilder] to build a +/// [EditorTextSelectionGestureDetector] for their [RawEditor]. The delegate provides /// the builder with information about the current state of the textfield. /// Based on these information, the builder adds the correct gesture handlers /// to the gesture detector. -/// -/// See also: -/// -/// * [TextField], which implements this delegate for the Material textfield. -/// * [CupertinoTextField], which implements this delegate for the Cupertino -/// textfield. abstract class EditorTextSelectionGestureDetectorBuilderDelegate { /// [GlobalKey] to the [EditableText] for which the /// [EditorTextSelectionGestureDetectorBuilder] will build a [EditorTextSelectionGestureDetector]. @@ -549,7 +543,23 @@ abstract class EditorTextSelectionGestureDetectorBuilderDelegate { bool get selectionEnabled; } -//TODO: Implement magnifier +/// Builds a [TextSelectionGestureDetector] to wrap an [RawEditor]. +/// +/// The class implements sensible defaults for many user interactions +/// with an [RawEditor] (see the documentation of the various gesture handler +/// methods, e.g. [onTapDown], [onForcePressStart], etc.). Subclasses of +/// [EditorTextSelectionGestureDetectorBuilder] can change the behavior performed in +/// responds to these gesture events by overriding the corresponding handler +/// methods of this class. +/// +/// The resulting [TextSelectionGestureDetector] to wrap an [RawEditor] is +/// obtained by calling [buildGestureDetector]. +/// +/// A [EditorTextSelectionGestureDetectorBuilder] must be provided a +/// [EditorTextSelectionGestureDetectorBuilderDelegate], from which information about +/// the [RawEditor] may be obtained. Typically, the [State] of the widget +/// that builds the [RawEditor] implements this interface, and then passes +/// itself as the [delegate]. class EditorTextSelectionGestureDetectorBuilder { /// Creates a [EditorTextSelectionGestureDetectorBuilder]. EditorTextSelectionGestureDetectorBuilder({