insertTemplate method

void insertTemplate(
  1. LatexTemplate template
)

Insert a template and position the cursor at the template's placeholder

Implementation

void insertTemplate(LatexTemplate template) {
  final expanded = template.expand();

  if (!_selection.isCollapsed) {
    _deleteSelectionInternal();
  }

  final currentOffset = _selection.baseOffset;
  final before = _text.substring(0, currentOffset);
  final after = _text.substring(currentOffset);
  _text = before + expanded.text + after;

  _selection = TextSelection.collapsed(
    offset: currentOffset + expanded.cursorDelta,
  );

  _reparse();
  notifyListeners();
}