1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-04 14:55:51 +03:00

shift cursor position by line number width on horizontal scroll

Этот коммит содержится в:
rhysd
2024-08-02 18:24:31 +09:00
родитель 19c32cefc5
Коммит 871577a20b

Просмотреть файл

@@ -81,6 +81,13 @@ impl Viewport {
}
impl<'a> TextArea<'a> {
fn lnum_width(&self) -> u8 {
if self.line_number_style().is_none() {
return 0;
}
num_digits(self.lines().len()) + 2
}
#[inline]
fn text_widget(&'a self, top_row: usize, height: usize) -> Text<'a> {
let lines_len = self.lines().len();
@@ -122,7 +129,8 @@ impl Widget for &TextArea<'_> {
let cursor = self.cursor();
let (top_row, top_col) = self.viewport.scroll_top();
let top_row = next_scroll_top(top_row, cursor.0 as u16, height);
let top_col = next_scroll_top(top_col, cursor.1 as u16, width);
let scroll_width = width.saturating_sub(self.lnum_width() as _);
let top_col = next_scroll_top(top_col, cursor.1 as u16, scroll_width);
let (text, style) = if !self.placeholder.is_empty() && self.is_empty() {
(self.placeholder_widget(), self.placeholder_style)