@@ -9,8 +9,8 @@ pub(crate) fn get_input(config: Option<&Config>, name: &str, default: &str) -> R
9
9
for mut value in input. split_whitespace ( ) . map ( String :: from) {
10
10
let mut modifiers = vec ! [ ] ;
11
11
12
- if let Some ( index ) = value. to_lowercase ( ) . find ( "shift+" ) {
13
- modifiers . push ( "Shift" ) ;
12
+ let shift_index = value. to_lowercase ( ) . find ( "shift+" ) ;
13
+ if let Some ( index ) = shift_index {
14
14
value. replace_range ( index..index + 6 , "" ) ;
15
15
}
16
16
if let Some ( index) = value. to_lowercase ( ) . find ( "control+" ) {
@@ -22,45 +22,53 @@ pub(crate) fn get_input(config: Option<&Config>, name: &str, default: &str) -> R
22
22
value. replace_range ( index..index + 4 , "" ) ;
23
23
}
24
24
25
- values. push ( format ! (
26
- "{}{}" ,
27
- modifiers. join( "" ) ,
28
- match value. to_lowercase( ) . as_ref( ) {
29
- "backspace" => String :: from( "Backspace" ) ,
30
- "backtab" => String :: from( "BackTab" ) ,
31
- "delete" => String :: from( "Delete" ) ,
32
- "down" => String :: from( "Down" ) ,
33
- "end" => String :: from( "End" ) ,
34
- "enter" => String :: from( "Enter" ) ,
35
- "esc" => String :: from( "Esc" ) ,
36
- "home" => String :: from( "Home" ) ,
37
- "insert" => String :: from( "Insert" ) ,
38
- "left" => String :: from( "Left" ) ,
39
- "pagedown" => String :: from( "PageDown" ) ,
40
- "pageup" => String :: from( "PageUp" ) ,
41
- "right" => String :: from( "Right" ) ,
42
- "tab" => String :: from( "Tab" ) ,
43
- "up" => String :: from( "Up" ) ,
44
- v => {
45
- if v. len( ) > 1 {
46
- // allow F{number} values
47
- if v. starts_with( 'f' ) && v[ 1 ..] . parse:: <u8 >( ) . is_ok( ) {
48
- v. to_uppercase( )
49
- }
50
- else {
51
- return Err ( ConfigError :: new(
52
- name,
53
- input. as_str( ) ,
54
- ConfigErrorCause :: InvalidKeyBinding ,
55
- ) ) ;
56
- }
57
- }
58
- else {
59
- value
60
- }
61
- } ,
25
+ let mut key = match value. to_lowercase ( ) . as_ref ( ) {
26
+ "backspace" => String :: from ( "Backspace" ) ,
27
+ "backtab" => String :: from ( "BackTab" ) ,
28
+ "delete" => String :: from ( "Delete" ) ,
29
+ "down" => String :: from ( "Down" ) ,
30
+ "end" => String :: from ( "End" ) ,
31
+ "enter" => String :: from ( "Enter" ) ,
32
+ "esc" => String :: from ( "Esc" ) ,
33
+ "home" => String :: from ( "Home" ) ,
34
+ "insert" => String :: from ( "Insert" ) ,
35
+ "left" => String :: from ( "Left" ) ,
36
+ "pagedown" => String :: from ( "PageDown" ) ,
37
+ "pageup" => String :: from ( "PageUp" ) ,
38
+ "right" => String :: from ( "Right" ) ,
39
+ "tab" => String :: from ( "Tab" ) ,
40
+ "up" => String :: from ( "Up" ) ,
41
+ v => {
42
+ let v_len = v. chars ( ) . count ( ) ;
43
+ // allow F{number} values
44
+ if v_len > 1 && v. starts_with ( 'f' ) && v[ 1 ..] . parse :: < u8 > ( ) . is_ok ( ) {
45
+ v. to_uppercase ( )
46
+ }
47
+ else if v_len == 1 {
48
+ value
49
+ }
50
+ else {
51
+ return Err ( ConfigError :: new (
52
+ name,
53
+ input. as_str ( ) ,
54
+ ConfigErrorCause :: InvalidKeyBinding ,
55
+ ) ) ;
56
+ }
57
+ } ,
58
+ } ;
59
+
60
+ // Shift support was partially removed, due to Shift not being universally reported, but still maintain
61
+ // some backwards compatibility with printable characters
62
+ if shift_index. is_some ( ) {
63
+ if key. len ( ) == 1 {
64
+ key = key. to_uppercase ( ) ;
65
+ }
66
+ else {
67
+ modifiers. push ( "Shift" ) ;
62
68
}
63
- ) ) ;
69
+ }
70
+
71
+ values. push ( format ! ( "{}{}" , modifiers. join( "" ) , key) ) ;
64
72
}
65
73
Ok ( values)
66
74
}
@@ -75,7 +83,9 @@ mod tests {
75
83
use crate :: testutils:: { invalid_utf, with_git_config} ;
76
84
77
85
#[ rstest]
78
- #[ case:: single( "a" , "a" ) ]
86
+ #[ case:: single_lower( "a" , "a" ) ]
87
+ #[ case:: single_upper( "A" , "A" ) ]
88
+ #[ case:: single_non_ascii( "ẞ" , "ẞ" ) ]
79
89
#[ case:: backspace( "backspace" , "Backspace" ) ]
80
90
#[ case:: backtab( "backtab" , "BackTab" ) ]
81
91
#[ case:: delete( "delete" , "Delete" ) ]
@@ -97,16 +107,19 @@ mod tests {
97
107
#[ case:: modifier_character_uppercase( "Control+A" , "ControlA" ) ]
98
108
#[ case:: modifier_character_number( "Control+1" , "Control1" ) ]
99
109
#[ case:: modifier_character_special( "Control++" , "Control+" ) ]
110
+ #[ case:: modifier_character_non_ascii( "Control+ẞ" , "Controlẞ" ) ]
100
111
#[ case:: modifier_character( "Control+a" , "Controla" ) ]
101
112
#[ case:: modifier_special( "Control+End" , "ControlEnd" ) ]
102
113
#[ case:: modifier_function( "Control+F32" , "ControlF32" ) ]
103
- #[ case:: modifier_control_alt_shift_lowercase( "alt+shift+control+end" , "ShiftControlAltEnd " ) ]
104
- #[ case:: modifier_control_alt_shift_mixedcase( "aLt+shIft+conTrol+eNd" , "ShiftControlAltEnd " ) ]
105
- #[ case:: modifier_control_alt_shift_out_of_order_1( "Alt+Shift+Control+End" , "ShiftControlAltEnd " ) ]
106
- #[ case:: modifier_control_alt_shift_out_of_order_2( "Shift+Control+Alt+End" , "ShiftControlAltEnd " ) ]
114
+ #[ case:: modifier_control_alt_shift_lowercase( "alt+shift+control+end" , "ControlAltShiftEnd " ) ]
115
+ #[ case:: modifier_control_alt_shift_mixedcase( "aLt+shIft+conTrol+eNd" , "ControlAltShiftEnd " ) ]
116
+ #[ case:: modifier_control_alt_shift_out_of_order_1( "Alt+Shift+Control+End" , "ControlAltShiftEnd " ) ]
117
+ #[ case:: modifier_control_alt_shift_out_of_order_2( "Shift+Control+Alt+End" , "ControlAltShiftEnd " ) ]
107
118
#[ case:: modifier_only_shift( "Shift+End" , "ShiftEnd" ) ]
108
119
#[ case:: modifier_only_control( "Control+End" , "ControlEnd" ) ]
109
- #[ case:: multiple( "a b c d" , "a,b,c,d" ) ]
120
+ #[ case:: shift_with_printable_lower( "Shift+a" , "A" ) ]
121
+ #[ case:: shift_with_printable_upper( "Shift+A" , "A" ) ]
122
+ #[ case:: multiple( "a b ẞ c d" , "a,b,ẞ,c,d" ) ]
110
123
#[ case:: multiple_with_modifiers( "Control+End Control+A" , "ControlEnd,ControlA" ) ]
111
124
fn read_value ( #[ case] binding : & str , #[ case] expected : & str ) {
112
125
with_git_config ( & [ "[test]" , format ! ( "value = {binding}" ) . as_str ( ) ] , |git_config| {
0 commit comments