|
@@ -102,10 +102,9 @@ class RenderEditableProxyBox extends RenderBox
|
102
|
102
|
set showCursor(ValueNotifier<bool> value) {
|
103
|
103
|
assert(value != null);
|
104
|
104
|
if (_showCursor == value) return;
|
105
|
|
- // TODO: only mark to repaint if cursor is collapsed and inside this box.
|
106
|
|
- if (attached) _showCursor.removeListener(markNeedsPaint);
|
|
105
|
+ if (attached) _showCursor.removeListener(markNeedsCursorPaint);
|
107
|
106
|
_showCursor = value;
|
108
|
|
- if (attached) _showCursor.addListener(markNeedsPaint);
|
|
107
|
+ if (attached) _showCursor.addListener(markNeedsCursorPaint);
|
109
|
108
|
markNeedsPaint();
|
110
|
109
|
}
|
111
|
110
|
|
|
@@ -131,8 +130,13 @@ class RenderEditableProxyBox extends RenderBox
|
131
|
130
|
/// Returns `true` if current selection is collapsed, located within
|
132
|
131
|
/// this paragraph and is visible according to tick timer.
|
133
|
132
|
bool get isCaretVisible {
|
|
133
|
+ return _showCursor.value && containsCaret;
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ /// Returns `true` if current selection is collapsed and located
|
|
137
|
+ /// within this paragraph.
|
|
138
|
+ bool get containsCaret {
|
134
|
139
|
if (!_selection.isCollapsed) return false;
|
135
|
|
- if (!_showCursor.value) return false;
|
136
|
140
|
|
137
|
141
|
final int start = node.documentOffset;
|
138
|
142
|
final int end = start + node.length;
|
|
@@ -147,6 +151,12 @@ class RenderEditableProxyBox extends RenderBox
|
147
|
151
|
return intersectsWithSelection(_selection);
|
148
|
152
|
}
|
149
|
153
|
|
|
154
|
+ void markNeedsCursorPaint() {
|
|
155
|
+ if (containsCaret) {
|
|
156
|
+ markNeedsPaint();
|
|
157
|
+ }
|
|
158
|
+ }
|
|
159
|
+
|
150
|
160
|
//
|
151
|
161
|
// Overridden members of RenderBox
|
152
|
162
|
//
|
|
@@ -154,13 +164,13 @@ class RenderEditableProxyBox extends RenderBox
|
154
|
164
|
@override
|
155
|
165
|
void attach(PipelineOwner owner) {
|
156
|
166
|
super.attach(owner);
|
157
|
|
- _showCursor.addListener(markNeedsPaint);
|
|
167
|
+ _showCursor.addListener(markNeedsCursorPaint);
|
158
|
168
|
_renderContext.addBox(this);
|
159
|
169
|
}
|
160
|
170
|
|
161
|
171
|
@override
|
162
|
172
|
void detach() {
|
163
|
|
- _showCursor.removeListener(markNeedsPaint);
|
|
173
|
+ _showCursor.removeListener(markNeedsCursorPaint);
|
164
|
174
|
_renderContext.removeBox(this);
|
165
|
175
|
super.detach();
|
166
|
176
|
}
|