Commit graph

226 commits

Author SHA1 Message Date
Ryota
5bb3700717 fix(tui): prevent Kitty protocol base layout key from causing false shortcut matches
With the Kitty keyboard protocol (flag 4), terminals report both the
logical key codepoint and the physical base layout key (PC-101 QWERTY
position). The key matching logic in matchesKittySequence matched
against both unconditionally, which caused a single keypress to match
multiple shortcuts on remapped keyboard layouts.

For example, on a Dvorak layout with xremap, pressing Ctrl+K sends
CSI 107::118;5u (codepoint=107 'k', base layout=118 'v'). The
unconditional base layout match made this also match Ctrl+V, which is
bound to pasteImage. Since CustomEditor checks app-level keybindings
(pasteImage) before editor keybindings (deleteToLineEnd), Ctrl+K was
silently intercepted by the paste image handler instead of deleting
to end of line. The same issue affects symbol keys, as Dvorak also
remaps symbols to different physical positions (e.g., '/' sits where
'[' is on QWERTY).

The fix restricts base layout key matching to cases where the codepoint
is not a recognized Latin letter (a-z) or symbol (/, -, [, ;, etc.).
When the codepoint is already a recognized key, it is authoritative and
the base layout key is ignored. This preserves non-Latin layout support
(Ctrl+К on a Russian layout still matches Ctrl+K via base layout key
107) while preventing false matches from differing physical key
positions on remapped layouts.

Both matchesKittySequence and parseKey are updated with the same logic.
2026-02-01 01:25:00 +01:00
Sviatoslav Abakumov
d075291b08
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
2026-01-31 22:52:47 +01:00
Marc Krenn
39c898d7c9
fix(tui): auto-clear empty rows when content shrinks (#1095)
- Add height change detection (analogous to existing width detection)
- Auto-detect when content shrinks below maxLinesRendered and trigger
  full re-render to clear leftover empty rows
- Only triggers when no overlays are active (overlays need padding)

Fixes empty rows appearing below footer when:
- Closing /tree or other selectors
- Clearing multi-line editor content
- Any component shrinking

Also adds regression tests for resize handling and content shrinkage.
2026-01-30 20:45:34 +01:00
Mario Zechner
836e852af1 Fixes #1099 2026-01-30 18:19:16 +01:00
Mario Zechner
abd0c47b03 perf(tui): use startsWith short-circuit in isImageLine 2026-01-30 17:07:43 +01:00
Dave dV
2339d7b5ac fix(tui): isImageLine should detect image escape sequences anywhere in line
Changed isImageLine() from using startsWith() to includes() to detect
Kitty and iTerm2 image escape sequences anywhere in a line, not just
at the start. This prevents TUI width checks from failing on lines
containing image data, which could cause crashes when rendering tool
results with images (e.g., when reading image files).

Also added comprehensive test coverage for isImageLine() including:
- Both iTerm2 and Kitty protocols
- Regression tests for long lines and terminals without image support
- Negative cases to ensure no false positives

Fixes crash: 'Rendered line exceeds terminal width' when image
escape sequences appear in output.
2026-01-30 10:07:22 +00:00
Fero
20ca6836b0
fix(tui): blockquote multiline rendering and wrapping (#1073)
* fix(tui): blockquote multiline rendering and wrapping

Fix two bugs in blockquote rendering:

1. ANSI codes split incorrectly on newlines - when text tokens contain
   newlines, applyDefaultStyle() wrapped the entire string including the
   newline in ANSI codes. Any caller splitting by \n would break the codes.
   Fixed by splitting text by newlines before styling in renderInlineTokens().

2. Wrapped blockquote lines lost the │ border - long blockquote lines
   that wrapped to multiple lines only had the border on the first line.
   Fixed by wrapping within the blockquote case and adding border to each line.

* test(tui): add test for inline formatting inside blockquotes
2026-01-30 03:02:38 +01:00
4h9fbZ
ab37d661af
feat(tui): jump to line start/end when pressing up/down at boundaries (#1050)
When cursor is on the first visual line and up is pressed, jump to
start of line instead of doing nothing. When cursor is on the last
visual line and down is pressed, jump to end of line instead of doing
nothing. This matches standard behavior in most native text inputs.
2026-01-30 02:42:24 +01:00
Can Bölük
4058346a64
perf(tui): optimize image line detection and box cache (#1084)
- Add isImageLine() to terminal-image.ts with single startsWith check based on detected terminal protocol
- Replace dual includes() checks in tui.ts with imported isImageLine()
- Add image line handling to markdown.ts to skip wrapping and margins for image escapes
- Consolidate Box cache into RenderCache type with childLines/width/bgSample/lines fields
- Use in-place mutation in applyLineResets() to avoid array allocation
2026-01-30 02:25:19 +01:00
Nathan Igo
902473797d
feat(tui,coding-agent): add ctrl+b/ctrl+f cursor navigation keybindings (#1053) 2026-01-30 01:43:54 +01:00
Sviatoslav Abakumov
c5d16fe456
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
2026-01-30 01:42:14 +01:00
Mario Zechner
f181385859 fix(tui): avoid duplicating quotes during autocomplete 2026-01-30 00:26:24 +01:00
Mario Zechner
1665636fbe fix(tui): close quoted directory paths during autocomplete 2026-01-30 00:20:14 +01:00
Mario Zechner
dc8539a001 fix(tui): support quoted paths with spaces in autocomplete
Fixes #1077
2026-01-30 00:11:12 +01:00
Colin Mason
b212314f45 feat: add autocompleteMaxVisible setting for configurable dropdown height 2026-01-29 03:16:52 +01:00
Sviatoslav Abakumov
b54d689ec1
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.
2026-01-29 02:48:09 +01:00
Sviatoslav Abakumov
d57a26c88b
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.
2026-01-29 02:47:15 +01:00
Mario Zechner
81be81328c feat(tui,coding-agent): add shell-style keybindings alt+b, alt+f, ctrl+d
- Add alt+b/alt+f as alternative bindings for cursorWordLeft/cursorWordRight
- Add ctrl+d as alternative binding for deleteCharForward
- Fix ctrl+d in custom editor to perform delete when text is present
  (previously it was always consumed, even with non-empty input)

Closes #1043

Co-authored-by: Jason Ish <ish@unx.ca>
2026-01-29 00:21:39 +01:00
Thomas Mustier
e7b9209daf
fix(tui): improve table rendering with row dividers and min width (#997)
* fix(tui): improve table rendering

* fix(tui): handle narrow table widths
2026-01-28 02:42:08 +01:00
mom
fb693fbc90 perf(tui): scan only bottom terminal height lines in extractCursorPosition 2026-01-28 01:40:57 +00:00
mom
9d47747ff6 perf(tui): early-out extractCursorPosition when cursor is above visible viewport 2026-01-28 01:37:43 +00:00
Can Bölük
a8f33fd630
perf(tui): optimized extractCursorPosition to scan lines in reverse order (#1004)
- Optimized extractCursorPosition to scan lines in reverse order for improved performance.
2026-01-28 02:34:50 +01:00
Sviatoslav Abakumov
1224b31135
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.
2026-01-28 02:12:18 +01:00
Mario Zechner
a6f9c3cf0d fix(tui): fix scrollback overwrite when appending lines past viewport
Appended lines were not committed to terminal scrollback because the
renderer used cursor movement (CSI B) and carriage return without
linefeed. This caused earlier content to be overwritten when the
viewport filled up.

Changes:
- For appended lines, emit \r\n to create real scrollback lines
- When target row is below viewport, scroll with \r\n before positioning
- Add PI_TUI_WRITE_LOG env var for debugging raw ANSI output
- Add fullRedraws readonly property to TUI class
- Add viewport-overwrite-repro.ts test script

fixes #954
2026-01-26 16:51:28 +01:00
Nico Bailon
c565fa9af8
fix(tui): keep overlays centered across resizes (#950) 2026-01-26 09:43:16 +01:00
aos
225fcb3830
feat: make session selector keybindings configurable (#948)
I lost my ability to select up and down in the session selector because
of some hardcoded keybindings again... So, I am adding these
configurable keybindings so I can `ctrl+p` to select up :-)

### Changes

Adds 4 new keybinding actions for the session picker (/resume):
- `toggleSessionPath` (ctrl+p) - toggle path display
- `toggleSessionSort` (ctrl+r) - toggle sort mode
- `deleteSession` (ctrl+d) - delete selected session
- `deleteSessionNoninvasive` (ctrl+backspace) - delete when query empty

Refactors session-selector to use `kb.matches()` instead of hardcoded key checks.
2026-01-25 20:08:11 +01:00
Sviatoslav Abakumov
beb1455cab
fix(tui): move lastAction handling out of setTextInternal()
The caller is responsible for doing that.
2026-01-25 17:50:55 +04:00
Sviatoslav Abakumov
609095b0b6
fix(tui): refactor the multi-line insertion handling 2026-01-25 17:50:50 +04:00
Sviatoslav Abakumov
7d2d170c1b
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.
2026-01-25 17:28:54 +04:00
Mario Zechner
79ded84d46
Merge pull request #936 from Perlence/fix/extension-editor-padding-x
fix(coding-agent): propagate paddingX to custom editors
2026-01-24 20:48:41 +01:00
Sviatoslav Abakumov
2bbc255237
fix(coding-agent): propagate paddingX to custom editors
setCustomEditorComponent() was not copying the paddingX setting from
the default editor to extension-provided editors. Also propagate live
changes from the settings callback.
2026-01-24 21:00:14 +04:00
Sviatoslav Abakumov
b5ab90f837
fix(tui): reserve 1 column for cursor in word wrap width 2026-01-24 17:41:10 +04:00
Sviatoslav Abakumov
9090268b7d
fix(tui): rewrite word wrap as single-pass with backtracking 2026-01-23 22:31:41 +04:00
Mario Zechner
f42deae13e fix(tui): gate slash menu to empty input 2026-01-22 23:12:33 +01:00
Mario Zechner
fbd6b7f9ba fix(tui): prevent image ID collisions between modules
- allocateImageId() now returns random IDs instead of sequential
- Static images no longer auto-allocate IDs (transient display)
- Only explicit imageId usage (like DOSBox) gets tracked IDs
- Suppress emulators exit logging in DOSBox dispose

Fixes image replacement bug when extension and main app both
allocated sequential IDs starting at 1.
2026-01-22 04:52:55 +01:00
Mario Zechner
df1d5c40ea fix(tui): proper Kitty image ID management and cleanup
- Add allocateImageId() to generate unique image IDs
- Add deleteKittyImage() and deleteAllKittyImages() functions
- Image component now tracks its ID and has dispose() method
- renderImage() returns imageId for tracking
- DOSBox: reuse single image ID for all frames, delete on dispose

Fixes image accumulation hitting terminal quota and lingering
images after component close.
2026-01-22 04:39:58 +01:00
Mario Zechner
b7cef51f3f fix(tui): don't add space after directory completion for @ file attachments 2026-01-21 23:48:41 +01:00
Richard Gill
7dc652f304
Autocomplete allow searchs with /'s like: folder1/folder2 (#882)
* Extend fd autocomplete tests

* Renamed fixture type in autocomplete test
2026-01-21 23:23:51 +01:00
Michael Renner
620239bd3f
fix(tui): prevent duplicate URL display for autolinked emails (#888)
Autolinked emails like user@example.com were rendered as
'user@example.com (mailto:user@example.com)' because the comparison
token.text === token.href failed (text lacks mailto: prefix).

Now strips mailto: prefix before comparing, so autolinked emails
display without redundant URL in parentheses.
2026-01-21 23:20:00 +01:00
Mario Zechner
565488fde6 fix(tui): fix viewport tracking and cursor positioning for overlays and content shrink
- Add maxLinesRendered to track terminal's working area (grows with content, only resets on full clear)
- Fix viewport calculation: use maxLinesRendered instead of cursorRow for correct viewport bounds
- Separate cursorRow (end of content for viewport calc) from hardwareCursorRow (actual cursor position)
- Refactor full render into fullRender(clear) helper to reduce duplication
- Fix shrink-clearing: properly clear extra lines when content shrinks
- Add PI_TUI_DEBUG=1 env var for render debugging (writes to /tmp/tui/)

The core issue was that after partial renders (e.g., overlay show/hide), the viewport
calculation used cursorRow which reflected where rendering stopped, not where content
ended. This caused incorrect viewport bounds, leading to cursor movement into scrollback
(unreachable) or rendering at wrong positions.

Additionally, when content shrank (e.g., selector dismissed), the terminal still had
the old lines as blank space. maxLinesRendered tracks this so viewport calculations
account for the terminal's actual working area.
2026-01-20 23:30:53 +01:00
Sviatoslav Abakumov
698aea34bd
feat(tui): add Alt+Delete as hotkey for Delete word forwards (#878)
* feat(tui): add Alt+Delete as hotkey for delete word forwards

* docs(coding-agent): update keybindings table with Alt+Delete
2026-01-20 23:03:44 +01:00
Michael Renner
20c7b5fed4
feat(tui, coding-agent): add configurable code block indent setting (#855)
Add markdown.codeBlockIndent setting to customize indentation prefix for
rendered code blocks. Default remains 2 spaces for visual clarity, but
setting to empty string removes indentation for easier copy/paste of
code snippets to scripts, editors, or other tools.

Changes:
- tui: add optional codeBlockIndent to MarkdownTheme interface
- coding-agent: add MarkdownSettings with codeBlockIndent property
- coding-agent: compose theme with settings at call sites (no global state)
- coding-agent: update message components to accept optional MarkdownTheme

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
2026-01-19 22:36:03 +01:00
Armin Ronacher
d37b5a52d7
More fuzzy finder (#860) 2026-01-19 22:22:51 +01:00
Sviatoslav Abakumov
fb1242829d feat(tui): add legacy terminal support for Ctrl+symbol keys
Ctrl+\ sends ASCII 28 (File Separator) in legacy terminals. This is
commonly used as SIGQUIT in Unix.

Ctrl+] sends ASCII 29 (Group Separator) in legacy terminals. This is
commonly used as the telnet escape character.

Ctrl+_ sends ASCII 31 (Unit Separator) in legacy terminals. On US
keyboards, - and _ are on the same physical key, so this also functions
as an alias for Ctrl+-.
2026-01-19 00:18:47 +01:00
Sviatoslav Abakumov
6bde679a5f fix(tui): use the non-null assertion operator instead of assert() 2026-01-19 00:18:47 +01:00
Sviatoslav Abakumov
bacf334bc4 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.
2026-01-19 00:18:47 +01:00
Mario Zechner
18d9d9d704 fix(tui): document kill ring and reset history 2026-01-17 21:12:48 +01:00
Sviatoslav Abakumov
505894f4ea 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.
2026-01-17 21:11:20 +01:00
Sviatoslav Abakumov
9fb7434a06 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
2026-01-17 21:11:20 +01:00
Sviatoslav Abakumov
bafddc27ed feat(tui): add legacy Alt+letter key sequence support
In legacy terminal mode (non-Kitty protocol), Alt+key is sent as ESC
followed by the key character. This was only supported for specific keys
(space, backspace, arrows) but not for regular letters.

Add support for Alt+letter sequences to enable keybindings like Alt+Y.
2026-01-17 21:11:20 +01:00