Pass _caretPrototype to prevent cache miss (#46720)

This commit is contained in:
Gary Qian
2019-12-20 06:46:49 +09:00
committed by GitHub
parent 3fe6668849
commit b011ea5468
9 changed files with 90 additions and 2 deletions

View File

@@ -170,6 +170,8 @@ class TextPainter {
void markNeedsLayout() {
_paragraph = null;
_needsLayout = true;
_previousCaretPosition = null;
_previousCaretPrototype = null;
}
/// The (potentially styled) text to paint.

View File

@@ -365,7 +365,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final Offset startOffset = _textPainter.getOffsetForCaret(
TextPosition(offset: _selection.start, affinity: _selection.affinity),
Rect.zero,
_caretPrototype,
);
// TODO(justinmc): https://github.com/flutter/flutter/issues/31495
// Check if the selection is visible with an approximation because a
@@ -381,7 +381,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final Offset endOffset = _textPainter.getOffsetForCaret(
TextPosition(offset: _selection.end, affinity: _selection.affinity),
Rect.zero,
_caretPrototype,
);
_selectionEndInViewport.value = visibleRegion
.inflate(visibleRegionSlop)