@@ -196,6 +196,18 @@ pub fn handle_event(
196196 command_queue. push_back ( Command :: Io ( IoCommand :: FetchSearchQuery ) ) ;
197197 }
198198 #[ cfg( feature = "search" ) ]
199+ Command :: UserInput ( InputEvent :: ToggleSmartCase ) => {
200+ p. search_state . smart_case = !p. search_state . smart_case ;
201+ if let Some ( ref term) = p. search_state . search_term {
202+ let pat = term. as_str ( ) ;
203+ p. search_state . search_term = search:: compile_regex ( pat, p. search_state . smart_case ) ;
204+ p. reformat_display ( ) ;
205+ command_queue. push_back ( Command :: Io ( IoCommand :: RedrawDisplay ) ) ;
206+ }
207+ p. format_prompt ( ) ;
208+ command_queue. push_back ( Command :: Io ( IoCommand :: RedrawPrompt ) ) ;
209+ }
210+ #[ cfg( feature = "search" ) ]
199211 Command :: UserInput ( InputEvent :: NextMatch | InputEvent :: MoveToNextMatch ( 1 ) )
200212 if p. search_state . search_term . is_some ( ) =>
201213 {
@@ -378,6 +390,8 @@ pub fn handle_event(
378390 Command :: SetRunNoOverflow ( val) => p. run_no_overflow = val,
379391 #[ cfg( feature = "search" ) ]
380392 Command :: IncrementalSearchCondition ( cb) => p. search_state . incremental_search_condition = cb,
393+ #[ cfg( feature = "search" ) ]
394+ Command :: SetSmartCase ( sc) => p. search_state . smart_case = sc,
381395 Command :: SetInputClassifier ( clf) => p. input_classifier = clf,
382396 #[ cfg( feature = "clipboard" ) ]
383397 Command :: SetClipboardHandler ( handler) => p. clipboard_handler = Some ( handler) ,
@@ -469,12 +483,14 @@ pub fn handle_io_command(
469483 drop ( active) ;
470484 cvar. notify_one ( ) ;
471485
486+ p. search_state . smart_case = search_result. smart_case ;
472487 // If we only have compiled regex cached, use that otherwise compile the original
473488 // string query if its not empty
474489 p. search_state . search_term = if search_result. compiled_regex . is_some ( ) {
475490 search_result. compiled_regex
476491 } else if !search_result. string . is_empty ( ) {
477- let compiled_regex = regex:: Regex :: new ( & search_result. string ) . ok ( ) ;
492+ let compiled_regex =
493+ search:: compile_regex ( & search_result. string , p. search_state . smart_case ) ;
478494 if compiled_regex. is_none ( ) {
479495 command_queue. push_back ( Command :: SendMessage (
480496 "Invalid regular expression. Press Enter" . to_string ( ) ,
@@ -636,7 +652,7 @@ mod tests {
636652 & is_exited,
637653 ) ;
638654 assert ! ( ps. help_state. is_none( ) ) ;
639- assert_eq ! ( is_exited. load( std:: sync:: atomic:: Ordering :: SeqCst ) , false ) ;
655+ assert ! ( ! is_exited. load( std:: sync:: atomic:: Ordering :: SeqCst ) ) ;
640656 assert_eq ! ( ps. screen. orig_text, "original text\n " ) ;
641657 }
642658
@@ -841,6 +857,7 @@ mod tests {
841857
842858 #[ test]
843859 #[ cfg( feature = "search" ) ]
860+ #[ allow( clippy:: trivial_regex) ]
844861 fn search_navigation_with_no_matches_does_not_panic ( ) {
845862 let mut ps = PagerState :: new ( ) . unwrap ( ) ;
846863 ps. search_state . search_term = Some ( regex:: Regex :: new ( "nonexistent" ) . unwrap ( ) ) ;
@@ -849,15 +866,15 @@ mod tests {
849866
850867 // NextMatch with empty search_idx should not panic
851868 handle_event (
852- Command :: UserInput ( InputEvent :: NextMatch ) ,
869+ Command :: UserInput ( InputEvent :: MoveToNextMatch ( 1 ) ) ,
853870 & mut ps,
854871 & mut command_queue,
855872 & Arc :: new ( AtomicBool :: new ( false ) ) ,
856873 ) ;
857874
858875 // PrevMatch with empty search_idx should not panic
859876 handle_event (
860- Command :: UserInput ( InputEvent :: PrevMatch ) ,
877+ Command :: UserInput ( InputEvent :: MoveToPrevMatch ( 1 ) ) ,
861878 & mut ps,
862879 & mut command_queue,
863880 & Arc :: new ( AtomicBool :: new ( false ) ) ,
@@ -879,4 +896,39 @@ mod tests {
879896 & Arc :: new ( AtomicBool :: new ( false ) ) ,
880897 ) ;
881898 }
899+
900+ #[ test]
901+ #[ cfg( feature = "search" ) ]
902+ fn test_toggle_and_set_smart_case ( ) {
903+ let mut ps = PagerState :: new ( ) . unwrap ( ) ;
904+ assert ! ( !ps. search_state. smart_case) ;
905+ let mut command_queue = CommandQueue :: new_zero ( ) ;
906+
907+ // Toggle via UserInput
908+ handle_event (
909+ Command :: UserInput ( InputEvent :: ToggleSmartCase ) ,
910+ & mut ps,
911+ & mut command_queue,
912+ & Arc :: new ( AtomicBool :: new ( false ) ) ,
913+ ) ;
914+ assert ! ( ps. search_state. smart_case) ;
915+
916+ // Toggle again
917+ handle_event (
918+ Command :: UserInput ( InputEvent :: ToggleSmartCase ) ,
919+ & mut ps,
920+ & mut command_queue,
921+ & Arc :: new ( AtomicBool :: new ( false ) ) ,
922+ ) ;
923+ assert ! ( !ps. search_state. smart_case) ;
924+
925+ // Explicit set
926+ handle_event (
927+ Command :: SetSmartCase ( true ) ,
928+ & mut ps,
929+ & mut command_queue,
930+ & Arc :: new ( AtomicBool :: new ( false ) ) ,
931+ ) ;
932+ assert ! ( ps. search_state. smart_case) ;
933+ }
882934}
0 commit comments