Browse Source

Imroved caret position on images

Anatoly Pulyaevskiy 6 years ago
parent
commit
fb86bfb76a
1 changed files with 5 additions and 3 deletions
  1. 5
    3
      packages/zefyr/lib/src/widgets/image.dart

+ 5
- 3
packages/zefyr/lib/src/widgets/image.dart View File

@@ -105,8 +105,9 @@ class RenderEditableImage extends RenderBox
105 105
     _node = value;
106 106
   }
107 107
 
108
+  // TODO: Customize caret height offset instead of adjusting here by 2px.
108 109
   @override
109
-  double get preferredLineHeight => size.height - kPaddingBottom;
110
+  double get preferredLineHeight => size.height - kPaddingBottom + 2.0;
110 111
 
111 112
   @override
112 113
   SelectionOrder get selectionOrder => SelectionOrder.foreground;
@@ -169,9 +170,10 @@ class RenderEditableImage extends RenderBox
169 170
   @override
170 171
   Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) {
171 172
     final pos = position.offset - node.documentOffset;
172
-    Offset caretOffset = Offset.zero;
173
+    Offset caretOffset = _childOffset - new Offset(kHorizontalPadding, 0.0);
173 174
     if (pos == 1) {
174
-      caretOffset = caretOffset + new Offset(size.width - 1.0, 0.0);
175
+      caretOffset = caretOffset +
176
+          new Offset(_lastChildSize.width + kHorizontalPadding, 0.0);
175 177
     }
176 178
     return caretOffset;
177 179
   }