handleKey method

bool handleKey(
  1. KeyEvent event
)

Handles a key event for text input.

Returns true if text or cursor state changed (useful for re-rendering). Handles typing, backspace and horizontal arrows. Recognized no-op keys return false here; text bindings consume them to prevent command fallthrough.

Does NOT handle: Enter, Esc, Tab (these are typically handled by the parent prompt).

Implementation

bool handleKey(KeyEvent event) {
  final printable = event.printableText;
  if (printable != null) return insert(printable);
  switch (event.type) {
    case KeyEventType.backspace:
      return backspace();

    case KeyEventType.arrowLeft:
      if (cursorAtStart) return false;
      moveCursor(-1);
      return true;

    case KeyEventType.arrowRight:
      if (cursorAtEnd) return false;
      moveCursor(1);
      return true;

    default:
      return false;
  }
}