Browse Source

fix links clickable offset

lucky1213 4 years ago
parent
commit
fa6787ff62

+ 1
- 1
packages/zefyr/example/lib/src/images.dart View File

126
   @override
126
   @override
127
   void onLinkTap(ZefyrLinkEntity value) {
127
   void onLinkTap(ZefyrLinkEntity value) {
128
     // return
128
     // return
129
-    print('The word touched is 123123');
129
+    print(value.text);
130
   }
130
   }
131
 }
131
 }
132
 
132
 

+ 2
- 2
packages/zefyr/lib/src/widgets/selection.dart View File

267
       if (_scope.controller.getStyleForSelection(selection).contains(NotusAttribute.link)) {
267
       if (_scope.controller.getStyleForSelection(selection).contains(NotusAttribute.link)) {
268
         // 当前点击的是link
268
         // 当前点击的是link
269
         var position = paragraph.getRenderBoxPositionForOffset(localPoint);
269
         var position = paragraph.getRenderBoxPositionForOffset(localPoint);
270
-        // 此处加1是点击text尾,不算点中
270
+        // 第一个字符和最后一个字符将不触发onTap
271
         final TextSpan span = paragraph.text.getSpanForPosition(TextPosition(
271
         final TextSpan span = paragraph.text.getSpanForPosition(TextPosition(
272
-          offset: position.offset + 1,
272
+          offset: position.offset == 0 ? position.offset - 1 : position.offset + 1,
273
           affinity: position.affinity,
273
           affinity: position.affinity,
274
         ));
274
         ));
275
         final recognizer = (span?.recognizer as TapGestureRecognizer);
275
         final recognizer = (span?.recognizer as TapGestureRecognizer);