@@ -355,69 +355,69 @@ fn run_app_loop(
355355 loop {
356356 terminal. draw ( |f| draw_ui ( f, app) ) ?;
357357
358- if let Event :: Key ( key) = event:: read ( ) ? {
359- if key. kind == KeyEventKind :: Press {
360- // Handle Ctrl+Q to quit
361- if key. code == KeyCode :: Char ( 'q' )
362- && key
363- . modifiers
364- . contains ( crossterm:: event:: KeyModifiers :: CONTROL )
365- {
366- return Ok ( ( ) ) ;
367- }
358+ if let Event :: Key ( key) = event:: read ( ) ?
359+ && key. kind == KeyEventKind :: Press
360+ {
361+ // Handle Ctrl+Q to quit
362+ if key. code == KeyCode :: Char ( 'q' )
363+ && key
364+ . modifiers
365+ . contains ( crossterm:: event:: KeyModifiers :: CONTROL )
366+ {
367+ return Ok ( ( ) ) ;
368+ }
368369
369- // Handle Tab to switch focus.
370- if matches ! ( key. code, KeyCode :: Tab | KeyCode :: BackTab ) {
371- app. input_focus = match app. input_focus {
372- InputFocus :: Regex => InputFocus :: Sample ,
373- InputFocus :: Sample => InputFocus :: Regex ,
374- } ;
375- continue ;
376- }
370+ // Handle Tab to switch focus.
371+ if matches ! ( key. code, KeyCode :: Tab | KeyCode :: BackTab ) {
372+ app. input_focus = match app. input_focus {
373+ InputFocus :: Regex => InputFocus :: Sample ,
374+ InputFocus :: Sample => InputFocus :: Regex ,
375+ } ;
376+ continue ;
377+ }
377378
378- // Escape will focus the Regex field back again.
379- if matches ! ( key. code, KeyCode :: Esc ) {
380- app. input_focus = InputFocus :: Regex ;
381- continue ;
382- }
379+ // Escape will focus the Regex field back again.
380+ if matches ! ( key. code, KeyCode :: Esc ) {
381+ app. input_focus = InputFocus :: Regex ;
382+ continue ;
383+ }
383384
384- // Intercept PageUp/PageDown in Sample pane to move by one page height
385- if matches ! ( app. input_focus, InputFocus :: Sample ) {
386- match key. code {
387- KeyCode :: PageUp | KeyCode :: PageDown => {
388- let page = std:: cmp:: max ( app. sample_view_height , 1 ) ;
389- let ( row, col) = app. sample_textarea . cursor ( ) ;
390- let rows_len = app. sample_textarea . lines ( ) . len ( ) ;
391- let target_row_u16 = match key. code {
392- KeyCode :: PageUp => ( row as u16 ) . saturating_sub ( page) ,
393- KeyCode :: PageDown => {
394- let max_row = rows_len. saturating_sub ( 1 ) as u16 ;
395- let r = ( row as u16 ) . saturating_add ( page) ;
396- if r > max_row { max_row } else { r }
397- }
398- _ => row as u16 ,
399- } ;
400- let target_col_u16 = col as u16 ;
401- app. sample_textarea
402- . move_cursor ( CursorMove :: Jump ( target_row_u16, target_col_u16) ) ;
403- continue ;
404- }
405- _ => { }
385+ // Intercept PageUp/PageDown in Sample pane to move by one page height
386+ if matches ! ( app. input_focus, InputFocus :: Sample ) {
387+ match key. code {
388+ KeyCode :: PageUp | KeyCode :: PageDown => {
389+ let page = std:: cmp:: max ( app. sample_view_height , 1 ) ;
390+ let ( row, col) = app. sample_textarea . cursor ( ) ;
391+ let rows_len = app. sample_textarea . lines ( ) . len ( ) ;
392+ let target_row_u16 = match key. code {
393+ KeyCode :: PageUp => ( row as u16 ) . saturating_sub ( page) ,
394+ KeyCode :: PageDown => {
395+ let max_row = rows_len. saturating_sub ( 1 ) as u16 ;
396+ let r = ( row as u16 ) . saturating_add ( page) ;
397+ if r > max_row { max_row } else { r }
398+ }
399+ _ => row as u16 ,
400+ } ;
401+ let target_col_u16 = col as u16 ;
402+ app. sample_textarea
403+ . move_cursor ( CursorMove :: Jump ( target_row_u16, target_col_u16) ) ;
404+ continue ;
406405 }
406+ _ => { }
407407 }
408+ }
408409
409- // Convert crossterm event to tui-textarea input
410- let input = Input :: from ( Event :: Key ( key) ) ;
410+ // Convert crossterm event to tui-textarea input
411+ let input = Input :: from ( Event :: Key ( key) ) ;
411412
412- // Handle input based on current mode
413- match app. input_focus {
414- InputFocus :: Regex => {
415- app. regex_textarea . input ( input) ;
416- app. compile_regex ( ) ; // TODO: Do this in a worker thread.
417- }
418- InputFocus :: Sample => {
419- app. sample_textarea . input ( input) ;
420- }
413+ // Handle input based on current mode
414+ match app. input_focus {
415+ InputFocus :: Regex => {
416+ app. regex_textarea . input ( input) ;
417+ app. compile_regex ( ) ; // TODO: Do this in a worker thread.
418+ }
419+ InputFocus :: Sample => {
420+ app. sample_textarea . input ( input) ;
421421 }
422422 }
423423 }
0 commit comments