|
@@ -16,6 +16,7 @@ import 'editable_box.dart';
|
16
|
16
|
import 'image.dart' show RenderEditableImage;
|
17
|
17
|
import 'rich_text.dart' show RenderZefyrParagraph;
|
18
|
18
|
import 'scope.dart';
|
|
19
|
+
|
19
|
20
|
/// Selection overlay controls selection handles and other gestures.
|
20
|
21
|
class ZefyrSelectionOverlay extends StatefulWidget {
|
21
|
22
|
const ZefyrSelectionOverlay({Key key, @required this.controls})
|
|
@@ -253,7 +254,7 @@ class _ZefyrSelectionOverlayState extends State<ZefyrSelectionOverlay>
|
253
|
254
|
WidgetsBinding.instance.hitTest(result, globalPoint);
|
254
|
255
|
|
255
|
256
|
RenderEditableProxyBox box = _getEditableBox(result);
|
256
|
|
-
|
|
257
|
+
|
257
|
258
|
box ??= _scope.renderContext.closestBoxForGlobalPoint(globalPoint);
|
258
|
259
|
if (box == null) return null;
|
259
|
260
|
|
|
@@ -266,7 +267,9 @@ class _ZefyrSelectionOverlayState extends State<ZefyrSelectionOverlay>
|
266
|
267
|
// 如果是link或者image
|
267
|
268
|
if (box?.child is RenderZefyrParagraph) {
|
268
|
269
|
RenderZefyrParagraph paragraph = box.child;
|
269
|
|
- if (_scope.controller.getStyleForSelection(selection).contains(NotusAttribute.link)) {
|
|
270
|
+ if (_scope.controller
|
|
271
|
+ .getStyleForSelection(selection)
|
|
272
|
+ .contains(NotusAttribute.link)) {
|
270
|
273
|
// 当前点击的是link
|
271
|
274
|
var spanPosition = paragraph.getRenderBoxPositionForOffset(localPoint);
|
272
|
275
|
// // 第一个字符和最后一个字符将不触发onTap
|
|
@@ -275,14 +278,16 @@ class _ZefyrSelectionOverlayState extends State<ZefyrSelectionOverlay>
|
275
|
278
|
affinity: spanPosition.affinity,
|
276
|
279
|
));
|
277
|
280
|
if (span != null) {
|
278
|
|
- if (paragraph.getPositionHasRenderBox(spanPosition, span.text.length)) {
|
|
281
|
+ if (paragraph.getPositionHasRenderBox(
|
|
282
|
+ spanPosition, span.text.length)) {
|
279
|
283
|
final recognizer = (span?.recognizer as TapGestureRecognizer);
|
280
|
284
|
if (recognizer != null) {
|
281
|
285
|
print('当前点击的是link');
|
282
|
286
|
// 关闭键盘 触发tap,改变光标,但不弹出键盘
|
283
|
287
|
_scope.closeKeyboard();
|
284
|
288
|
recognizer.onTap();
|
285
|
|
- _scope.controller.updateSelection(selection, source: ChangeSource.remote);
|
|
289
|
+ _scope.controller
|
|
290
|
+ .updateSelection(selection, source: ChangeSource.remote);
|
286
|
291
|
return;
|
287
|
292
|
}
|
288
|
293
|
}
|
|
@@ -290,11 +295,14 @@ class _ZefyrSelectionOverlayState extends State<ZefyrSelectionOverlay>
|
290
|
295
|
}
|
291
|
296
|
} else if (box?.child is RenderEditableImage) {
|
292
|
297
|
RenderEditableImage image = box.child;
|
293
|
|
- if ((image.child as RenderPadding).child is RenderSemanticsGestureHandler) {
|
294
|
|
- RenderSemanticsGestureHandler gestureBox = (image.child as RenderPadding).child;
|
|
298
|
+ if ((image.child as RenderPadding).child
|
|
299
|
+ is RenderSemanticsGestureHandler) {
|
|
300
|
+ RenderSemanticsGestureHandler gestureBox =
|
|
301
|
+ (image.child as RenderPadding).child;
|
295
|
302
|
_scope.closeKeyboard();
|
296
|
303
|
gestureBox.onTap();
|
297
|
|
- _scope.controller.updateSelection(selection, source: ChangeSource.remote);
|
|
304
|
+ _scope.controller
|
|
305
|
+ .updateSelection(selection, source: ChangeSource.remote);
|
298
|
306
|
return;
|
299
|
307
|
}
|
300
|
308
|
}
|
|
@@ -323,7 +331,7 @@ class _ZefyrSelectionOverlayState extends State<ZefyrSelectionOverlay>
|
323
|
331
|
final localPoint = box.globalToLocal(globalPoint);
|
324
|
332
|
final position = box.getPositionForOffset(localPoint);
|
325
|
333
|
var word = box.getWordBoundary(position);
|
326
|
|
-
|
|
334
|
+
|
327
|
335
|
// if (box?.child is RenderZefyrParagraph) {
|
328
|
336
|
// RenderZefyrParagraph paragraph = box.child;
|
329
|
337
|
// if (_scope.controller.getStyleForSelection(TextSelection.collapsed(
|
|
@@ -522,18 +530,18 @@ class _SelectionHandleDriverState extends State<SelectionHandleDriver>
|
522
|
530
|
alignment: Alignment.topLeft,
|
523
|
531
|
width: interactiveRect.width,
|
524
|
532
|
height: interactiveRect.height,
|
525
|
|
- child:
|
526
|
|
- // RawGestureDetector(
|
527
|
|
- // behavior: HitTestBehavior.translucent,
|
528
|
|
- // gestures: <Type, GestureRecognizerFactory>{
|
529
|
|
- // CustomPanGestureRecognizer: GestureRecognizerFactoryWithHandlers<
|
530
|
|
- // CustomPanGestureRecognizer>(
|
531
|
|
- // () => CustomPanGestureRecognizer(
|
532
|
|
- // onPanDown: _handleDragStart, onPanUpdate: _handleDragUpdate),
|
533
|
|
- // (CustomPanGestureRecognizer instance) {},
|
534
|
|
- // ),
|
535
|
|
- // },
|
536
|
|
- GestureDetector(
|
|
533
|
+ child:
|
|
534
|
+ // RawGestureDetector(
|
|
535
|
+ // behavior: HitTestBehavior.translucent,
|
|
536
|
+ // gestures: <Type, GestureRecognizerFactory>{
|
|
537
|
+ // CustomPanGestureRecognizer: GestureRecognizerFactoryWithHandlers<
|
|
538
|
+ // CustomPanGestureRecognizer>(
|
|
539
|
+ // () => CustomPanGestureRecognizer(
|
|
540
|
+ // onPanDown: _handleDragStart, onPanUpdate: _handleDragUpdate),
|
|
541
|
+ // (CustomPanGestureRecognizer instance) {},
|
|
542
|
+ // ),
|
|
543
|
+ // },
|
|
544
|
+ GestureDetector(
|
537
|
545
|
behavior: HitTestBehavior.translucent,
|
538
|
546
|
dragStartBehavior: DragStartBehavior.start,
|
539
|
547
|
onPanStart: _handleDragStart,
|
|
@@ -630,6 +638,7 @@ class _SelectionToolbar extends StatefulWidget {
|
630
|
638
|
}
|
631
|
639
|
|
632
|
640
|
class _SelectionToolbarState extends State<_SelectionToolbar> {
|
|
641
|
+ final ClipboardStatusNotifier _clipboardStatus = kIsWeb ? null : ClipboardStatusNotifier();
|
633
|
642
|
TextSelectionControls get controls => widget.selectionOverlay.controls;
|
634
|
643
|
ZefyrScope get scope => widget.selectionOverlay.scope;
|
635
|
644
|
TextSelection get selection =>
|
|
@@ -681,12 +690,14 @@ class _SelectionToolbarState extends State<_SelectionToolbar> {
|
681
|
690
|
);
|
682
|
691
|
|
683
|
692
|
final toolbar = controls.buildToolbar(
|
684
|
|
- context,
|
685
|
|
- editingRegion,
|
686
|
|
- block.preferredLineHeight,
|
687
|
|
- midpoint,
|
688
|
|
- endpoints,
|
689
|
|
- widget.selectionOverlay);
|
|
693
|
+ context,
|
|
694
|
+ editingRegion,
|
|
695
|
+ block.preferredLineHeight,
|
|
696
|
+ midpoint,
|
|
697
|
+ endpoints,
|
|
698
|
+ widget.selectionOverlay,
|
|
699
|
+ _clipboardStatus,
|
|
700
|
+ );
|
690
|
701
|
return CompositedTransformFollower(
|
691
|
702
|
link: block.layerLink,
|
692
|
703
|
showWhenUnlinked: false,
|
|
@@ -730,4 +741,4 @@ class CustomPanGestureRecognizer extends OneSequenceGestureRecognizer {
|
730
|
741
|
|
731
|
742
|
@override
|
732
|
743
|
void didStopTrackingLastPointer(int pointer) {}
|
733
|
|
-}
|
|
744
|
+}
|