Skip to content

Commit e5103be

Browse files
committed
fix: fix the issue where line numbers are not fully displayed when exceeding 100,000
1 parent 08d9ce8 commit e5103be

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/app/sheet.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ impl AppState<'_> {
9292
self.current_search_idx = None;
9393
}
9494

95+
self.update_row_number_width();
96+
9597
self.add_notification(format!("Switched to sheet: {}", new_sheet_name));
9698
Ok(())
9799
}

src/app/state.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct AppState<'a> {
4242
pub sheet_cell_positions: HashMap<String, CellPosition>, // Store cell positions for each sheet
4343
pub clipboard: Option<String>, // Store copied/cut cell content
4444
pub g_pressed: bool, // Track if 'g' was pressed for 'gg' command
45+
pub row_number_width: usize, // Width for displaying row numbers
4546
pub search_query: String, // Current search query
4647
pub search_results: Vec<(usize, usize)>, // List of cells matching the search query
4748
pub current_search_idx: Option<usize>, // Index of current search result
@@ -101,6 +102,16 @@ impl AppState<'_> {
101102
// Initialize TextArea
102103
let text_area = TextArea::default();
103104

105+
// Calculate the width needed for row numbers based on the maximum row number
106+
let max_rows = workbook.get_current_sheet().max_rows;
107+
let row_number_width = if max_rows < 10 {
108+
1
109+
} else {
110+
max_rows.to_string().len()
111+
};
112+
// Ensure a minimum width of 4 for row numbers
113+
let row_number_width = row_number_width.max(4);
114+
104115
Ok(Self {
105116
workbook,
106117
file_path,
@@ -118,6 +129,7 @@ impl AppState<'_> {
118129
sheet_cell_positions,
119130
clipboard: None,
120131
g_pressed: false,
132+
row_number_width,
121133
search_query: String::new(),
122134
search_results: Vec::new(),
123135
current_search_idx: None,
@@ -142,6 +154,14 @@ impl AppState<'_> {
142154
}
143155
}
144156

157+
/// Updates the row number width based on the maximum row number in the current sheet
158+
pub fn update_row_number_width(&mut self) {
159+
let max_rows = self.workbook.get_current_sheet().max_rows;
160+
let width = max_rows.to_string().len();
161+
// Ensure a minimum width of 4 for row numbers
162+
self.row_number_width = width.max(4);
163+
}
164+
145165
pub fn adjust_info_panel_height(&mut self, delta: isize) {
146166
let new_height = (self.info_panel_height as isize + delta).clamp(6, 16) as usize;
147167
if new_height != self.info_panel_height {

src/ui/render.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ fn update_visible_area(app_state: &mut AppState, area: Rect) {
7272
// Ensure the selected column is visible
7373
app_state.ensure_column_visible(app_state.selected_cell.1);
7474

75+
// Update row number width based on the maximum row number
76+
app_state.update_row_number_width();
77+
7578
// Calculate available width for columns (subtract row numbers and borders)
76-
let available_width = (area.width as usize).saturating_sub(7); // 5 for row numbers + 2 for borders
79+
let available_width = (area.width as usize).saturating_sub(app_state.row_number_width + 2); // row_number_width + 2 for borders
7780

7881
// Calculate how many columns can fit in the available width
7982
let mut visible_cols = 0;
@@ -143,7 +146,7 @@ fn draw_spreadsheet(f: &mut Frame, app_state: &AppState, area: Rect) {
143146
let end_col = start_col + app_state.visible_cols - 1;
144147

145148
let mut constraints = Vec::with_capacity(app_state.visible_cols + 1);
146-
constraints.push(Constraint::Length(5)); // Row header width
149+
constraints.push(Constraint::Length(app_state.row_number_width as u16)); // Dynamic row header width
147150

148151
for col in start_col..=end_col {
149152
constraints.push(Constraint::Length(app_state.get_column_width(col) as u16));

0 commit comments

Comments
 (0)