@@ -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 {
0 commit comments