getPositionAbove method
Returns the position within the text which is on the line above the given
position
.
The position
parameter must be relative to the node
content.
Primarily used with multi-line or soft-wrapping text.
Can return null
which indicates that the position
is at the topmost
line in the text already.
Implementation
@override
TextPosition? getPositionAbove(TextPosition position) {
assert(position.offset < container.length);
final child = childAtPosition(position);
final childLocalPosition = TextPosition(offset: position.offset - child.container.offset);
final result = child.getPositionAbove(childLocalPosition);
if (result != null) {
return TextPosition(offset: result.offset + child.container.offset);
}
final sibling = childBefore(child);
if (sibling == null) {
return null;
}
final caretOffset = child.getOffsetForCaret(childLocalPosition);
final testPosition = TextPosition(offset: sibling.container.length - 1);
final testOffset = sibling.getOffsetForCaret(testPosition);
final finalOffset = Offset(caretOffset.dx, testOffset.dy);
return TextPosition(offset: sibling.container.offset + sibling.getPositionForOffset(finalOffset).offset);
}