Skip to content

Commit

Permalink
Remove unused codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-P committed Dec 6, 2023
1 parent e0ff5d5 commit 99bb395
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 72 deletions.
63 changes: 0 additions & 63 deletions packages/fleather/lib/src/rendering/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class RenderEditor extends RenderEditableContainerBox
}) : _document = document,
_hasFocus = hasFocus,
_selection = selection,
_extendSelectionOrigin = selection,
_startHandleLayerLink = startHandleLayerLink,
_endHandleLayerLink = endHandleLayerLink,
_cursorController = cursorController,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 19 additions & 9 deletions packages/fleather/lib/src/widgets/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,11 @@ class _TextSelectionHandleOverlayState extends State<TextSelectionHandleOverlay>
/// 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].
Expand All @@ -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({
Expand Down

0 comments on commit 99bb395

Please sign in to comment.