tui: fix cursor position calculation

The cursor index is into self.input, but the rendered buffer contains
the prompt prepended to the first line. Need to add prompt.len() to
get the correct character position when scanning the buffer.
This commit is contained in:
ProofOfConcept 2026-03-19 00:45:07 -04:00
parent ec79d60fbd
commit 6a7ec9732b
2 changed files with 3 additions and 2 deletions

View file

@ -821,6 +821,7 @@ impl App {
// Cursor position: scan the rendered buffer to find where the cursor should be.
// This matches ratatui's actual word wrapping instead of trying to simulate it.
let buffer = frame.buffer_mut();
let cursor_char = prompt.len() + self.cursor; // Total chars from start (prompt + input)
let mut char_count = 0usize;
let mut cursor_x = input_area.x;
let mut cursor_y = input_area.y;
@ -833,7 +834,7 @@ impl App {
// Count visible characters (skip zero-width and empty)
if !symbol.is_empty() {
let width = symbol.width();
if char_count + width > self.cursor {
if char_count + width > cursor_char {
// Found the cursor position
cursor_x = x;
cursor_y = y;