backspaceWord method

bool backspaceWord()

Deletes word before cursor (Ctrl+Backspace behavior).

Returns true if any characters were deleted.

Implementation

bool backspaceWord() {
  if (_cursorPosition == 0) return false;

  final t = text;
  var pos = _cursorPosition - 1;

  // Skip trailing whitespace
  while (pos > 0 && t[pos] == ' ') {
    pos--;
  }

  // Delete until start of word
  while (pos > 0 && t[pos - 1] != ' ') {
    pos--;
  }

  final before = t.substring(0, pos);
  final after = t.substring(_cursorPosition);

  _buffer.clear();
  _buffer.write(before);
  _buffer.write(after);

  _cursorPosition = pos;
  return true;
}