@@ -474,19 +474,23 @@ pub fn rl(
474474 EventHandler :: Simple ( Cmd :: Insert ( 1 , "\n " . to_string ( ) ) ) ,
475475 ) ;
476476
477- // Add custom keybinding for Ctrl+J to insert a newline
477+ // Add custom keybinding for Ctrl+j to insert a newline
478478 rl. bind_sequence (
479479 KeyEvent ( KeyCode :: Char ( 'j' ) , Modifiers :: CTRL ) ,
480480 EventHandler :: Simple ( Cmd :: Insert ( 1 , "\n " . to_string ( ) ) ) ,
481481 ) ;
482482
483- // Add custom keybinding for Ctrl+F to accept hint (like fish shell)
483+ // Add custom keybinding for autocompletion hint acceptance (configurable)
484+ let autocompletion_key_char = match os. database . settings . get_string ( Setting :: AutocompletionKey ) {
485+ Some ( key) if key. len ( ) == 1 => key. chars ( ) . next ( ) . unwrap_or ( 'g' ) ,
486+ _ => 'g' , // Default to 'g' if setting is missing or invalid
487+ } ;
484488 rl. bind_sequence (
485- KeyEvent ( KeyCode :: Char ( 'f' ) , Modifiers :: CTRL ) ,
489+ KeyEvent ( KeyCode :: Char ( autocompletion_key_char ) , Modifiers :: CTRL ) ,
486490 EventHandler :: Simple ( Cmd :: CompleteHint ) ,
487491 ) ;
488492
489- // Add custom keybinding for Ctrl+T to toggle tangent mode (configurable)
493+ // Add custom keybinding for Ctrl+t to toggle tangent mode (configurable)
490494 let tangent_key_char = match os. database . settings . get_string ( Setting :: TangentModeKey ) {
491495 Some ( key) if key. len ( ) == 1 => key. chars ( ) . next ( ) . unwrap_or ( 't' ) ,
492496 _ => 't' , // Default to 't' if setting is missing or invalid
@@ -722,4 +726,35 @@ mod tests {
722726 let hint = hinter. hint ( line, pos, & ctx) ;
723727 assert_eq ! ( hint, None ) ;
724728 }
729+
730+ #[ tokio:: test]
731+ // If you get a unit test failure for key override, please consider using a new key binding instead.
732+ // The list of reserved keybindings here are the standard in UNIX world so please don't take them
733+ async fn test_no_emacs_keybindings_overridden ( ) {
734+ let ( sender, _) = tokio:: sync:: broadcast:: channel :: < PromptQuery > ( 1 ) ;
735+ let ( _, receiver) = tokio:: sync:: broadcast:: channel :: < PromptQueryResult > ( 1 ) ;
736+
737+ // Create a mock Os for testing
738+ let mock_os = crate :: os:: Os :: new ( ) . await . unwrap ( ) ;
739+ let mut test_editor = rl ( & mock_os, sender, receiver) . unwrap ( ) ;
740+
741+ // Reserved Emacs keybindings that should not be overridden
742+ let reserved_keys = [ 'a' , 'e' , 'f' , 'b' , 'k' ] ;
743+
744+ for & key in & reserved_keys {
745+ let key_event = KeyEvent ( KeyCode :: Char ( key) , Modifiers :: CTRL ) ;
746+
747+ // Try to bind and get the previous handler
748+ let previous_handler = test_editor. bind_sequence (
749+ key_event,
750+ EventHandler :: Simple ( Cmd :: Noop )
751+ ) ;
752+
753+ // If there was a previous handler, it means the key was already bound
754+ // (which could be our custom binding overriding Emacs)
755+ if previous_handler. is_some ( ) {
756+ panic ! ( "Ctrl+{} appears to be overridden (found existing binding)" , key) ;
757+ }
758+ }
759+ }
725760}
0 commit comments