QuillTextLink.prepare constructor

QuillTextLink.prepare(
  1. QuillController controller
)

Implementation

factory QuillTextLink.prepare(QuillController controller) {
  final link = _getLinkAttributeValue(controller);
  final index = controller.selection.start;

  String? text;
  if (link != null) {
    // text should be the link's corresponding text, not selection
    final leaf = controller.document.querySegmentLeafNode(index).leaf;
    if (leaf != null) {
      text = leaf.toPlainText();
    }
  }

  final len = controller.selection.end - index;
  text ??= len == 0 ? '' : controller.document.getPlainText(index, len);

  return QuillTextLink(text, link);
}