findOffsetOfLineBreak static method
Locates the first line break in a text node, or throws an exception if it cannot find one.
Implementation
static int findOffsetOfLineBreak(String nodeId, [Finder? superEditorFinder]) {
final documentLayout = findDocumentLayout(superEditorFinder);
final componentState = documentLayout.getComponentByNodeId(nodeId) as State;
late final GlobalKey textComponentKey;
if (componentState is ProxyDocumentComponent) {
textComponentKey = componentState.childDocumentComponentKey;
} else {
textComponentKey = componentState.widget.key as GlobalKey;
}
final textLayout = (textComponentKey.currentState as TextComponentState).textLayout;
if (textLayout.getLineCount() < 2) {
throw Exception('Specified node does not contain a line break');
}
return textLayout.getPositionAtEndOfLine(const TextPosition(offset: 0)).offset;
}