diff --git a/poc-agent/src/tui.rs b/poc-agent/src/tui.rs index 6f6c90b..0507068 100644 --- a/poc-agent/src/tui.rs +++ b/poc-agent/src/tui.rs @@ -821,7 +821,11 @@ 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) + + // Convert byte index to character index for the input portion + let input_chars_before_cursor = self.input[..self.cursor].chars().count(); + let cursor_char_pos = prompt.chars().count() + input_chars_before_cursor; + let mut char_count = 0usize; let mut cursor_x = input_area.x; let mut cursor_y = input_area.y; @@ -833,14 +837,13 @@ impl App { let symbol = cell.symbol(); // Count visible characters (skip zero-width and empty) if !symbol.is_empty() { - let width = symbol.width(); - if char_count + width > cursor_char { + if char_count == cursor_char_pos { // Found the cursor position cursor_x = x; cursor_y = y; break; } - char_count += width; + char_count += 1; } } }