toggleLinePrefix method

bool toggleLinePrefix(
  1. String prefix, {
  2. bool addSpaceWhenNonEmpty = true,
  3. bool skipBlankLinesWhenChecking = true,
})

Toggles prefix on the current line or selected block.

The prefix is inserted after leading indentation, and a single space is added before non-empty content when addSpaceWhenNonEmpty is true.

Implementation

bool toggleLinePrefix(
  String prefix, {
  bool addSpaceWhenNonEmpty = true,
  bool skipBlankLinesWhenChecking = true,
}) {
  if (prefix.isEmpty) return false;
  return _runEditFrame(() {
    _beginHistoryAction(_TextAreaHistoryAction.transform, breakChain: true);
    final result = textToggleLinePrefixDocument(
      document: _document,
      state: _currentLineStateSnapshot(),
      prefix: prefix,
      addSpaceWhenNonEmpty: addSpaceWhenNonEmpty,
      skipBlankLinesWhenChecking: skipBlankLinesWhenChecking,
    );
    if (!result.changed) {
      return false;
    }

    _recordUndoSnapshot();
    _applyOffsetCommandResult(result);
    return true;
  });
}