@@ -513,6 +513,50 @@ impl EnhancedTuiApp {
513513 }
514514 }
515515
516+ // Wrapper methods for pinned_columns (uses buffer system)
517+ fn get_pinned_columns ( & self ) -> Vec < usize > {
518+ if let Some ( buffer) = self . current_buffer ( ) {
519+ buffer. get_pinned_columns ( ) . clone ( )
520+ } else {
521+ self . pinned_columns . clone ( )
522+ }
523+ }
524+
525+ fn add_pinned_column ( & mut self , col : usize ) {
526+ if let Some ( buffer) = self . current_buffer_mut ( ) {
527+ buffer. add_pinned_column ( col) ;
528+ } else {
529+ if !self . pinned_columns . contains ( & col) {
530+ self . pinned_columns . push ( col) ;
531+ self . pinned_columns . sort ( ) ;
532+ }
533+ }
534+ }
535+
536+ fn remove_pinned_column ( & mut self , col : usize ) {
537+ if let Some ( buffer) = self . current_buffer_mut ( ) {
538+ buffer. remove_pinned_column ( col) ;
539+ } else {
540+ self . pinned_columns . retain ( |& c| c != col) ;
541+ }
542+ }
543+
544+ fn clear_pinned_columns ( & mut self ) {
545+ if let Some ( buffer) = self . current_buffer_mut ( ) {
546+ buffer. clear_pinned_columns ( ) ;
547+ } else {
548+ self . pinned_columns . clear ( ) ;
549+ }
550+ }
551+
552+ fn contains_pinned_column ( & self , col : usize ) -> bool {
553+ if let Some ( buffer) = self . current_buffer ( ) {
554+ buffer. get_pinned_columns ( ) . contains ( & col)
555+ } else {
556+ self . pinned_columns . contains ( & col)
557+ }
558+ }
559+
516560 fn get_filter_state ( & self ) -> & FilterState {
517561 & self . filter_state
518562 }
@@ -1484,7 +1528,7 @@ impl EnhancedTuiApp {
14841528 }
14851529 KeyCode :: Char ( 'P' ) => {
14861530 // Clear all pinned columns
1487- self . clear_pinned_columns ( ) ;
1531+ self . clear_all_pinned_columns ( ) ;
14881532 }
14891533 KeyCode :: Char ( 'C' ) => {
14901534 // Toggle compact mode with Shift+C
@@ -2735,31 +2779,24 @@ impl EnhancedTuiApp {
27352779
27362780 fn toggle_column_pin ( & mut self ) {
27372781 // Pin or unpin the current column
2738- if let Some ( pos) = self
2739- . pinned_columns
2740- . iter ( )
2741- . position ( |& x| x == self . get_current_column ( ) )
2742- {
2782+ let current_col = self . get_current_column ( ) ;
2783+ if self . contains_pinned_column ( current_col) {
27432784 // Column is already pinned, unpin it
2744- self . pinned_columns . remove ( pos ) ;
2745- self . set_status_message ( format ! ( "Column {} unpinned" , self . get_current_column ( ) + 1 ) ) ;
2785+ self . remove_pinned_column ( current_col ) ;
2786+ self . set_status_message ( format ! ( "Column {} unpinned" , current_col + 1 ) ) ;
27462787 } else {
27472788 // Pin the column (max 4 pinned columns)
2748- if self . pinned_columns . len ( ) < 4 {
2749- self . pinned_columns . push ( self . get_current_column ( ) ) ;
2750- self . pinned_columns . sort ( ) ; // Keep them in order
2751- self . set_status_message ( format ! (
2752- "Column {} pinned 📌" ,
2753- self . get_current_column( ) + 1
2754- ) ) ;
2789+ if self . get_pinned_columns ( ) . len ( ) < 4 {
2790+ self . add_pinned_column ( current_col) ;
2791+ self . set_status_message ( format ! ( "Column {} pinned 📌" , current_col + 1 ) ) ;
27552792 } else {
27562793 self . set_status_message ( "Maximum 4 pinned columns allowed" . to_string ( ) ) ;
27572794 }
27582795 }
27592796 }
27602797
2761- fn clear_pinned_columns ( & mut self ) {
2762- self . pinned_columns . clear ( ) ;
2798+ fn clear_all_pinned_columns ( & mut self ) {
2799+ self . clear_pinned_columns ( ) ;
27632800 self . set_status_message ( "All columns unpinned" . to_string ( ) ) ;
27642801 }
27652802
@@ -5238,10 +5275,10 @@ impl EnhancedTuiApp {
52385275 ) ) ;
52395276
52405277 // Show pinned columns count if any
5241- if !self . pinned_columns . is_empty ( ) {
5278+ if !self . get_pinned_columns ( ) . is_empty ( ) {
52425279 spans. push ( Span :: raw ( " | " ) ) ;
52435280 spans. push ( Span :: styled (
5244- format ! ( "📌{}" , self . pinned_columns . len( ) ) ,
5281+ format ! ( "📌{}" , self . get_pinned_columns ( ) . len( ) ) ,
52455282 Style :: default ( ) . fg ( Color :: Magenta ) ,
52465283 ) ) ;
52475284 }
@@ -5470,7 +5507,7 @@ impl EnhancedTuiApp {
54705507 let mut scrollable_indices: Vec < usize > = Vec :: new ( ) ;
54715508
54725509 for ( i, header) in headers. iter ( ) . enumerate ( ) {
5473- if self . pinned_columns . contains ( & i) {
5510+ if self . contains_pinned_column ( i) {
54745511 pinned_headers. push ( ( i, header) ) ;
54755512 } else {
54765513 scrollable_indices. push ( i) ;
@@ -5676,7 +5713,7 @@ impl EnhancedTuiApp {
56765713 } ;
56775714
56785715 // Add pin indicator for pinned columns
5679- let pin_indicator = if self . pinned_columns . contains ( actual_col_index) {
5716+ let pin_indicator = if self . contains_pinned_column ( * actual_col_index) {
56805717 "📌 "
56815718 } else {
56825719 ""
@@ -5822,7 +5859,7 @@ impl EnhancedTuiApp {
58225859 . borders ( Borders :: ALL )
58235860 . title ( format ! ( "Results ({} rows) - {} pinned, {} visible of {} | Viewport rows {}-{} (selected: {}) | Use h/l to scroll" ,
58245861 total_rows,
5825- self . pinned_columns . len( ) ,
5862+ self . get_pinned_columns ( ) . len( ) ,
58265863 visible_columns. len( ) ,
58275864 headers. len( ) ,
58285865 row_viewport_start + 1 ,
0 commit comments