Commit Graph

24 Commits

  • feat(tui): add sticky column for vertical cursor navigation (#1120)
    When moving up/down through lines of varying lengths, the editor now
    remembers the original column position and restores it when reaching a
    line long enough to accommodate it.
    
    Example: cursor at column 10, move up to a shorter line (cursor clamps
    to end), move up again to a longer line - cursor returns to column 10.
    
    Implementation:
    
    - Add preferredVisualCol instance property (nullable)
    - Set it when moving to a shorter line during vertical navigation
    - Clear it when arriving at a line that fits the preferred column
    - Clear it on any horizontal movement or editing via setCursorCol()
    - Detect line rewrap by checking if cursor is in middle of line
    - When pressing right at end of prompt, set preferredVisualCol so
      subsequent up/down navigation uses that column position
  • feat(tui): add character jump navigation (Ctrl+], Ctrl+Alt+]) (#1074)
    Add Bash/Readline-style character search:
    
    - Ctrl+] enters forward jump mode, awaits next character, jumps to it
    - Ctrl+Alt+] does the same but searches backward
    - Multi-line search
    - Case-sensitive matching
    - Pressing the hotkey again cancels; control chars cancel and fall
      through
  • A couple of autocomplete improvements (#1024)
    * fix(tui): keep file suggestions open when typing in Tab-triggered mode
    
    Previously, pressing Tab on an empty prompt or after a space would show
    file suggestions, but typing a letter would dismiss them because the
    text didn't look like a path pattern. Now the editor tracks whether
    autocomplete was triggered via Tab (force mode) or naturally (regular
    mode), and uses the appropriate suggestion method when updating.
    
    * fix(tui): hide autocomplete when backspacing slash command to empty
    
    Previously, typing / showed slash command suggestions, but pressing
    Backspace to delete it showed file suggestions instead of hiding all
    suggestions.
  • fix(tui): remove backslash input buffering (#1037)
    Instead of buffering `\` and waiting for the next key, let it be
    inserted immediately. On Enter, check if preceded by `\` and treat as
    newline.
    
    Removed backslash handling from the Input component entirely.
  • feat(tui): auto-apply single suggestion in force file autocomplete (#993)
    When Tab triggers file autocomplete and there's exactly one matching
    suggestion, apply it immediately without showing the menu. This makes
    path completion faster by eliminating the extra Tab press to confirm.
  • fix(tui): handle multi-line text in insertTextAtCursor()
    Add insertTextAtCursorInternal() to properly handle newlines by splitting
    lines at the cursor position.
    
    - Normalize line endings (CRLF/CR to LF)
    - Handle single-line and multi-line insertion
    - Position cursor at end of inserted text
    - Call onChange only once at the end
    
    Refactor handlePaste() to use insertTextAtCursorInternal() for
    multi-line pastes, while retaining character-by-character insertion for
    single-line pastes to preserve autocomplete triggering.
  • feat(tui): add undo support to Editor with the Ctrl+- hotkey
    Undo snapshots are captured for all edit operations:
    
    - Word insertion, backspace, forward delete
    - Word/line deletion (Ctrl+W, Ctrl+U, Ctrl+K, Alt+D)
    - Yank/yank-pop, paste, autocomplete completion
    - Cursor movement starts a new undo unit
    - setText() pushes snapshot when content changes
    
    Additionally, history browsing captures the undo state on first entry.
  • feat(tui): add Alt+D to delete word forward (kill)
    Adds deleteWordForward action bound to Alt+D, which deletes from cursor
    to the end of the current word and saves to kill ring for later yanking.
    Consecutive forward kills append to the same kill ring entry.
  • feat(tui): implement Emacs-style kill ring for Editor
    Add kill ring functionality with:
    
    - Ctrl+W/U/K save deleted text to kill ring
    - Ctrl+Y yanks (pastes) most recent deletion
    - Alt+Y cycles through kill ring (after Ctrl+Y)
    - Consecutive deletions accumulate into single entry
  • fix(tui): add vertical scrolling to Editor when content exceeds terminal height
    The Editor component now accepts TUI as the first constructor parameter,
    enabling it to query terminal dimensions. When content exceeds available
    height, the editor scrolls vertically keeping the cursor visible.
    
    Features:
    - Max editor height is 30% of terminal rows (minimum 5 lines)
    - Page Up/Down keys scroll by page size
    - Scroll indicators show lines above/below: ─── ↑ 5 more ───
    
    Breaking change: Editor constructor signature changed from
      new Editor(theme)
    to
      new Editor(tui, theme)
    
    fixes #732
  • feat(tui): implement word wrapping in Editor component
    Previously, the Editor component used character-level (grapheme-level)
    wrapping, which broke words mid-character at line boundaries. This
    created an ugly visual experience when typing or pasting long text.
    
    Now the Editor uses word-aware wrapping:
    - Wraps at word boundaries when possible
    - Falls back to character-level wrapping for tokens wider than the
      available width (e.g., long URLs)
    - Strips leading whitespace at line starts
    - Preserves multiple spaces within lines
    
    Added wordWrapLine() helper function that tokenizes text into words
    and whitespace runs, then builds chunks that fit within the specified
    width while respecting word boundaries.
    
    Also updated buildVisualLineMap() to use the same word wrapping logic
    for consistent cursor navigation.
    
    Added tests for:
    - Word boundary wrapping
    - Leading whitespace stripping
    - Long token (URL) character-level fallback
    - Multiple space preservation
    - Edge cases (empty string, exact fit)
  • Fix Ctrl+W to use standard readline word deletion behavior (#306)
    - Skip trailing whitespace before deleting word (readline behavior)
    - Make word navigation grapheme-aware using Intl.Segmenter
    - Add Ctrl+Left/Right and Alt+Left/Right word navigation to Input
    - Accept full Unicode input while rejecting control characters (C0/C1/DEL)
    - Extract shared utilities to utils.ts (getSegmenter, isWhitespaceChar, isPunctuationChar)
    - Fix unsafe cast in Editor.forceFileAutocomplete with runtime type check
    - Add comprehensive tests for word deletion and navigation
  • Fix editor crash with wide characters (emojis, CJK)
    Editor text wrapping now uses grapheme-aware width calculation instead
    of string length. Fixes crash when pasting text containing emojis like
     or CJK characters that are 2 terminal columns wide.
  • feat(tui): add prompt history navigation with Up/Down arrows
    Browse previously submitted prompts using Up/Down arrow keys, similar to
    shell history and Claude Code's prompt history feature.
    
    - Up arrow when editor is empty: browse to older prompts
    - Down arrow when browsing: return to newer prompts or clear editor
    - Cursor movement within multi-line history entries supported
    - History is session-scoped, stores up to 100 entries
    - Consecutive duplicates are not added to history
    
    Includes 15 new tests for history navigation behavior.