From f52fd11fcf4409cccbdd361ae6d8640f5a296905 Mon Sep 17 00:00:00 2001 From: singerdmx Date: Sat, 19 Dec 2020 00:53:36 -0800 Subject: [PATCH] Implement EditorTextSelectionGestureDetectorBuilder --- lib/widgets/delegate.dart | 84 ++++++++++++++++++++++++++++++++- lib/widgets/text_selection.dart | 9 ++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/lib/widgets/delegate.dart b/lib/widgets/delegate.dart index fd810b38..e4376ef0 100644 --- a/lib/widgets/delegate.dart +++ b/lib/widgets/delegate.dart @@ -1,4 +1,7 @@ import 'package:flutter/cupertino.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter_quill/models/documents/nodes/leaf.dart'; import 'editor.dart'; @@ -29,7 +32,12 @@ class EditorTextSelectionGestureDetectorBuilder { } onTapDown(TapDownDetails details) { -// getRenderEditor().handleTapDown(details); + getRenderEditor().handleTapDown(details); + + PointerDeviceKind kind = details.kind; + shouldShowSelectionToolbar = kind == null || + kind == PointerDeviceKind.touch || + kind == PointerDeviceKind.stylus; } onForcePressStart(ForcePressDetails details) { @@ -44,6 +52,80 @@ class EditorTextSelectionGestureDetectorBuilder { } } + onForcePressEnd(ForcePressDetails details) { + assert(delegate.getForcePressEnabled()); + getRenderEditor().selectWordsInRange( + details.globalPosition, + null, + SelectionChangedCause.forcePress, + ); + if (shouldShowSelectionToolbar) { + getEditor().showToolbar(); + } + } + + onSingleTapUp(TapUpDetails details) { + if (delegate.getSelectionEnabled()) { + getRenderEditor().selectWordEdge(SelectionChangedCause.tap); + } + } + + onSingleTapCancel() {} + + onSingleLongTapStart(LongPressStartDetails details) { + if (delegate.getSelectionEnabled()) { + getRenderEditor().selectPositionAt( + details.globalPosition, + null, + SelectionChangedCause.longPress, + ); + } + } + + onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { + if (delegate.getSelectionEnabled()) { + getRenderEditor().selectPositionAt( + details.globalPosition, + null, + SelectionChangedCause.longPress, + ); + } + } + + onSingleLongTapEnd(LongPressEndDetails details) { + if (shouldShowSelectionToolbar) { + getEditor().showToolbar(); + } + } + + onDoubleTapDown(TapDownDetails details) { + if (delegate.getSelectionEnabled()) { + getRenderEditor().selectWord(SelectionChangedCause.tap); + if (shouldShowSelectionToolbar) { + getEditor().showToolbar(); + } + } + } + + onDragSelectionStart(DragStartDetails details) { + getRenderEditor().selectPositionAt( + details.globalPosition, + null, + SelectionChangedCause.drag, + ); + } + + onDragSelectionUpdate( + DragStartDetails startDetails, DragUpdateDetails updateDetails) { + getRenderEditor().selectPositionAt( + startDetails.globalPosition, + updateDetails.globalPosition, + SelectionChangedCause.drag, + ); + } + + onDragSelectionEnd(DragEndDetails details) {} + Widget build(HitTestBehavior behavior, Widget child) { // TODO return null; diff --git a/lib/widgets/text_selection.dart b/lib/widgets/text_selection.dart index e7fe34f6..a4fd3e58 100644 --- a/lib/widgets/text_selection.dart +++ b/lib/widgets/text_selection.dart @@ -117,3 +117,12 @@ class EditorTextSelectionOverlay { _toolbarController.dispose(); } } + +class EditorTextSelectionGestureDetector extends StatefulWidget { + @override + State createState() { + // TODO: implement createState + throw UnimplementedError(); + } + +}