@@ -604,12 +604,7 @@ pub fn default_mouse_bindings() -> Vec<MouseBinding> {
604
604
)
605
605
}
606
606
607
- pub fn default_key_bindings (
608
- unprocessed_config_key_bindings : Vec < ConfigKeyBinding > ,
609
- use_navigation_key_bindings : bool ,
610
- use_splits : bool ,
611
- config_keyboard : ConfigKeyboard ,
612
- ) -> Vec < KeyBinding > {
607
+ pub fn default_key_bindings ( config : & rio_backend:: config:: Config ) -> Vec < KeyBinding > {
613
608
let mut bindings = bindings ! (
614
609
KeyBinding ;
615
610
Key :: Named ( Copy ) ; Action :: Copy ;
@@ -724,12 +719,15 @@ pub fn default_key_bindings(
724
719
) ) ;
725
720
726
721
bindings. extend ( platform_key_bindings (
727
- use_navigation_key_bindings ,
728
- use_splits ,
729
- config_keyboard ,
722
+ config . navigation . has_navigation_key_bindings ( ) ,
723
+ config . navigation . use_split ,
724
+ config . keyboard ,
730
725
) ) ;
731
726
732
- config_key_bindings ( unprocessed_config_key_bindings, bindings)
727
+ // Add hint bindings
728
+ bindings. extend ( create_hint_bindings ( & config. hints . rules ) ) ;
729
+
730
+ config_key_bindings ( config. bindings . keys . to_owned ( ) , bindings)
733
731
}
734
732
735
733
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -915,6 +913,87 @@ pub fn config_key_bindings(
915
913
bindings
916
914
}
917
915
916
+ /// Create hint bindings from configuration
917
+ pub fn create_hint_bindings (
918
+ hints_config : & [ rio_backend:: config:: hints:: Hint ] ,
919
+ ) -> Vec < KeyBinding > {
920
+ let mut hint_bindings = Vec :: new ( ) ;
921
+
922
+ for hint_config in hints_config {
923
+ if let Some ( binding_config) = & hint_config. binding {
924
+ // Parse key using the same logic as in convert()
925
+ let ( key, location) = match binding_config. key . to_lowercase ( ) . as_str ( ) {
926
+ // Letters
927
+ single_char if single_char. len ( ) == 1 => {
928
+ ( Key :: Character ( single_char. into ( ) ) , KeyLocation :: Standard )
929
+ }
930
+ // Named keys
931
+ "space" => ( Key :: Named ( Space ) , KeyLocation :: Standard ) ,
932
+ "enter" | "return" => ( Key :: Named ( Enter ) , KeyLocation :: Standard ) ,
933
+ "escape" | "esc" => ( Key :: Named ( Escape ) , KeyLocation :: Standard ) ,
934
+ "tab" => ( Key :: Named ( Tab ) , KeyLocation :: Standard ) ,
935
+ "backspace" => ( Key :: Named ( Backspace ) , KeyLocation :: Standard ) ,
936
+ "delete" => ( Key :: Named ( Delete ) , KeyLocation :: Standard ) ,
937
+ "insert" => ( Key :: Named ( Insert ) , KeyLocation :: Standard ) ,
938
+ "home" => ( Key :: Named ( Home ) , KeyLocation :: Standard ) ,
939
+ "end" => ( Key :: Named ( End ) , KeyLocation :: Standard ) ,
940
+ "pageup" => ( Key :: Named ( PageUp ) , KeyLocation :: Standard ) ,
941
+ "pagedown" => ( Key :: Named ( PageDown ) , KeyLocation :: Standard ) ,
942
+ "up" => ( Key :: Named ( ArrowUp ) , KeyLocation :: Standard ) ,
943
+ "down" => ( Key :: Named ( ArrowDown ) , KeyLocation :: Standard ) ,
944
+ "left" => ( Key :: Named ( ArrowLeft ) , KeyLocation :: Standard ) ,
945
+ "right" => ( Key :: Named ( ArrowRight ) , KeyLocation :: Standard ) ,
946
+ // Function keys
947
+ "f1" => ( Key :: Named ( F1 ) , KeyLocation :: Standard ) ,
948
+ "f2" => ( Key :: Named ( F2 ) , KeyLocation :: Standard ) ,
949
+ "f3" => ( Key :: Named ( F3 ) , KeyLocation :: Standard ) ,
950
+ "f4" => ( Key :: Named ( F4 ) , KeyLocation :: Standard ) ,
951
+ "f5" => ( Key :: Named ( F5 ) , KeyLocation :: Standard ) ,
952
+ "f6" => ( Key :: Named ( F6 ) , KeyLocation :: Standard ) ,
953
+ "f7" => ( Key :: Named ( F7 ) , KeyLocation :: Standard ) ,
954
+ "f8" => ( Key :: Named ( F8 ) , KeyLocation :: Standard ) ,
955
+ "f9" => ( Key :: Named ( F9 ) , KeyLocation :: Standard ) ,
956
+ "f10" => ( Key :: Named ( F10 ) , KeyLocation :: Standard ) ,
957
+ "f11" => ( Key :: Named ( F11 ) , KeyLocation :: Standard ) ,
958
+ "f12" => ( Key :: Named ( F12 ) , KeyLocation :: Standard ) ,
959
+ _ => {
960
+ tracing:: warn!(
961
+ "Unknown key '{}' in hint binding" ,
962
+ binding_config. key
963
+ ) ;
964
+ continue ;
965
+ }
966
+ } ;
967
+
968
+ // Parse modifiers
969
+ let mut mods = ModifiersState :: empty ( ) ;
970
+ for mod_str in & binding_config. mods {
971
+ match mod_str. to_lowercase ( ) . as_str ( ) {
972
+ "control" | "ctrl" => mods |= ModifiersState :: CONTROL ,
973
+ "shift" => mods |= ModifiersState :: SHIFT ,
974
+ "alt" | "option" => mods |= ModifiersState :: ALT ,
975
+ "super" | "cmd" | "command" => mods |= ModifiersState :: SUPER ,
976
+ _ => {
977
+ tracing:: warn!( "Unknown modifier '{}' in hint binding" , mod_str) ;
978
+ }
979
+ }
980
+ }
981
+
982
+ let hint_binding = KeyBinding {
983
+ trigger : BindingKey :: Keycode { key, location } ,
984
+ mods,
985
+ mode : BindingMode :: empty ( ) ,
986
+ notmode : BindingMode :: SEARCH | BindingMode :: VI ,
987
+ action : Action :: Hint ( std:: rc:: Rc :: new ( hint_config. clone ( ) ) ) ,
988
+ } ;
989
+
990
+ hint_bindings. push ( hint_binding) ;
991
+ }
992
+ }
993
+
994
+ hint_bindings
995
+ }
996
+
918
997
// Macos
919
998
#[ cfg( all( target_os = "macos" , not( test) ) ) ]
920
999
pub fn platform_key_bindings (
0 commit comments