Skip to content

Commit

Permalink
fix terminal cursor position calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
xubaiwang committed Oct 8, 2024
1 parent de16d45 commit 4615f84
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/views/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,39 +603,37 @@ impl InputField {
if !is_last || displayed_width + char_width > width {
if self.focused && selection.contains(i, y) {
self.cursor_style.queue(w, fit::ELLIPSIS)?;
displayed_width += 1;
// set terminal cursor position
terminal_cursor_pos = Some((
self.area.left + displayed_width as u16,
self.area.top + j,
));
} else {
normal_style.queue(w, fit::ELLIPSIS)?;
displayed_width += 1;
}
displayed_width += 1;
break;
}
}
if self.focused && selection.contains(i, y) {
self.cursor_style.queue(w, c)?;
displayed_width += char_width;
// set terminal cursor position
terminal_cursor_pos =
Some((self.area.left + displayed_width as u16, self.area.top + j));
} else {
displayed_width += char_width;
normal_style.queue(w, c)?;
}
displayed_width += char_width;
if displayed_width >= width {
break;
}
}
if displayed_width < width && cursor_at_end {
self.cursor_style.queue(w, ' ')?;
displayed_width += 1;
// set terminal cursor position
terminal_cursor_pos =
Some((self.area.left + displayed_width as u16, self.area.top + j));
displayed_width += 1;
}
while displayed_width < width {
normal_style.queue(w, ' ')?;
Expand Down

0 comments on commit 4615f84

Please sign in to comment.