Implement EditorTextSelectionGestureDetectorBuilder

pull/13/head
singerdmx 4 years ago
parent 2b82bae34e
commit f52fd11fcf
  1. 84
      lib/widgets/delegate.dart
  2. 9
      lib/widgets/text_selection.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;

@ -117,3 +117,12 @@ class EditorTextSelectionOverlay {
_toolbarController.dispose();
}
}
class EditorTextSelectionGestureDetector extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
throw UnimplementedError();
}
}

Loading…
Cancel
Save