findDeltaBetweenCharactersInTextNode static method

Offset findDeltaBetweenCharactersInTextNode(
  1. String nodeId,
  2. int textOffset1,
  3. int textOffset2, [
  4. Finder? superEditorFinder,
])

Calculates the delta between the center of the character at textOffset1 and and the center of the character at textOffset2 within the node with the given nodeId.

By default, this method expects a single SuperEditor in the widget tree and finds it byType. To specify one SuperEditor among many, pass a superEditorFinder.

Implementation

static Offset findDeltaBetweenCharactersInTextNode(String nodeId, int textOffset1, int textOffset2,
    [Finder? superEditorFinder]) {
  final docLayout = findDocumentLayout(superEditorFinder);
  final characterBoxStart = docLayout.getRectForPosition(
    DocumentPosition(nodeId: nodeId, nodePosition: TextNodePosition(offset: textOffset1)),
  );
  final characterBoxEnd = docLayout.getRectForPosition(
    DocumentPosition(nodeId: nodeId, nodePosition: TextNodePosition(offset: textOffset2)),
  );
  return characterBoxEnd!.center - characterBoxStart!.center;
}