Skip to content

Commit 404d79e

Browse files
p1024kClaude Opus 4.6
andcommitted
fix(tui): correct cursor position in input fields
Fixed cursor position calculation in TUI input components. The cursor was appearing on top of the last character instead of after it due to incorrect offset calculation. Changes: - app.rs: Fixed cursor position from area.x + 2 to area.x + 3 (accounting for left border + "> " prefix) - widgets/input.rs: Same fix for CommandInput widget - components/text_input.rs: Show underline cursor at end of text Co-Authored-By: Claude Opus 4.6 <noreply@openkeyring.com>
1 parent f44b564 commit 404d79e

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/tui/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,8 @@ impl TuiApp {
10851085

10861086
frame.render_widget(paragraph, area);
10871087

1088-
// Set cursor position
1089-
frame.set_cursor_position((area.x + 2 + self.input_buffer.len() as u16, area.y + 1));
1088+
// Set cursor position (area.x + 1 for left border, + 2 for "> " prefix, then cursor offset)
1089+
frame.set_cursor_position((area.x + 3 + self.input_buffer.len() as u16, area.y + 1));
10901090
}
10911091
}
10921092

src/tui/components/text_input.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,16 @@ impl Render for TextInput {
225225
if self.focused && area.width > 0 {
226226
let cursor_x = self.cursor.min(area.width as usize - 1);
227227
// 光标位置用下划线表示
228+
// Note: cursor_x is byte offset, but for ASCII it equals display width
228229
if self.cursor < self.text.len() {
230+
// Cursor within text - underline the character at cursor position
229231
buf[(area.x + cursor_x as u16, area.y)]
230232
.set_style(style.add_modifier(Modifier::UNDERLINED));
233+
} else {
234+
// Cursor at end of text - show underline cursor in empty space
235+
buf[(area.x + cursor_x as u16, area.y)]
236+
.set_char(' ')
237+
.set_style(style.add_modifier(Modifier::UNDERLINED));
231238
}
232239
}
233240
}

src/tui/widgets/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl CommandInput {
155155

156156
frame.render_widget(paragraph, area);
157157

158-
// Set cursor position
159-
frame.set_cursor_position((area.x + 2 + self.cursor as u16, area.y + 1));
158+
// Set cursor position (area.x + 1 for left border, + 2 for "> " prefix, then cursor offset)
159+
frame.set_cursor_position((area.x + 3 + self.cursor as u16, area.y + 1));
160160
}
161161
}

0 commit comments

Comments
 (0)