on master help sign in
simplify some keymap key names (#2677)
8351a82Henry
book/src/remapping.md−5
@@ -33,12 +33,7 @@ Control, Shift and Alt modifiers are encoded respectively with the prefixes
33| Backspace | `"backspace"` |
33| Backspace | `"backspace"` |
34| Space | `"space"` |
34| Space | `"space"` |
35| Return/Enter | `"ret"` |
35| Return/Enter | `"ret"` |
36−| < | `"lt"` |
37−| \> | `"gt"` |
38−| \+ | `"plus"` |
39| \- | `"minus"` |
36| \- | `"minus"` |
40−| ; | `"semicolon"` |
41−| % | `"percent"` |
42| Left | `"left"` |
37| Left | `"left"` |
43| Right | `"right"` |
38| Right | `"right"` |
44| Up | `"up"` |
39| Up | `"up"` |
helix-view/src/input.rs+18−20
@@ -41,12 +41,7 @@ pub(crate) mod keys {
41 pub(crate) const NULL: &str = "null";
41 pub(crate) const NULL: &str = "null";
42 pub(crate) const ESC: &str = "esc";
42 pub(crate) const ESC: &str = "esc";
43 pub(crate) const SPACE: &str = "space";
43 pub(crate) const SPACE: &str = "space";
44− pub(crate) const LESS_THAN: &str = "lt";
45− pub(crate) const GREATER_THAN: &str = "gt";
46− pub(crate) const PLUS: &str = "plus";
47 pub(crate) const MINUS: &str = "minus";
44 pub(crate) const MINUS: &str = "minus";
48− pub(crate) const SEMICOLON: &str = "semicolon";
49− pub(crate) const PERCENT: &str = "percent";
50}
45}
51
46
52impl fmt::Display for KeyEvent {
47impl fmt::Display for KeyEvent {
@@ -86,12 +81,7 @@ impl fmt::Display for KeyEvent {
86 KeyCode::Null => f.write_str(keys::NULL)?,
81 KeyCode::Null => f.write_str(keys::NULL)?,
87 KeyCode::Esc => f.write_str(keys::ESC)?,
82 KeyCode::Esc => f.write_str(keys::ESC)?,
88 KeyCode::Char(' ') => f.write_str(keys::SPACE)?,
83 KeyCode::Char(' ') => f.write_str(keys::SPACE)?,
89− KeyCode::Char('<') => f.write_str(keys::LESS_THAN)?,
90− KeyCode::Char('>') => f.write_str(keys::GREATER_THAN)?,
91− KeyCode::Char('+') => f.write_str(keys::PLUS)?,
92 KeyCode::Char('-') => f.write_str(keys::MINUS)?,
84 KeyCode::Char('-') => f.write_str(keys::MINUS)?,
93− KeyCode::Char(';') => f.write_str(keys::SEMICOLON)?,
94− KeyCode::Char('%') => f.write_str(keys::PERCENT)?,
95 KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?,
85 KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?,
96 KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?,
86 KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?,
97 };
87 };
@@ -119,12 +109,7 @@ impl UnicodeWidthStr for KeyEvent {
119 KeyCode::Null => keys::NULL.len(),
109 KeyCode::Null => keys::NULL.len(),
120 KeyCode::Esc => keys::ESC.len(),
110 KeyCode::Esc => keys::ESC.len(),
121 KeyCode::Char(' ') => keys::SPACE.len(),
111 KeyCode::Char(' ') => keys::SPACE.len(),
122− KeyCode::Char('<') => keys::LESS_THAN.len(),
123− KeyCode::Char('>') => keys::GREATER_THAN.len(),
124− KeyCode::Char('+') => keys::PLUS.len(),
125 KeyCode::Char('-') => keys::MINUS.len(),
112 KeyCode::Char('-') => keys::MINUS.len(),
126− KeyCode::Char(';') => keys::SEMICOLON.len(),
127− KeyCode::Char('%') => keys::PERCENT.len(),
128 KeyCode::F(1..=9) => 2,
113 KeyCode::F(1..=9) => 2,
129 KeyCode::F(_) => 3,
114 KeyCode::F(_) => 3,
130 KeyCode::Char(c) => c.width().unwrap_or(0),
115 KeyCode::Char(c) => c.width().unwrap_or(0),
@@ -168,12 +153,7 @@ impl std::str::FromStr for KeyEvent {
168 keys::NULL => KeyCode::Null,
153 keys::NULL => KeyCode::Null,
169 keys::ESC => KeyCode::Esc,
154 keys::ESC => KeyCode::Esc,
170 keys::SPACE => KeyCode::Char(' '),
155 keys::SPACE => KeyCode::Char(' '),
171− keys::LESS_THAN => KeyCode::Char('<'),
172− keys::GREATER_THAN => KeyCode::Char('>'),
173− keys::PLUS => KeyCode::Char('+'),
174 keys::MINUS => KeyCode::Char('-'),
156 keys::MINUS => KeyCode::Char('-'),
175− keys::SEMICOLON => KeyCode::Char(';'),
176− keys::PERCENT => KeyCode::Char('%'),
177 single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()),
157 single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()),
178 function if function.len() > 1 && function.starts_with('F') => {
158 function if function.len() > 1 && function.starts_with('F') => {
179 let function: String = function.chars().skip(1).collect();
159 let function: String = function.chars().skip(1).collect();
@@ -336,6 +316,14 @@ mod test {
336 modifiers: KeyModifiers::NONE
316 modifiers: KeyModifiers::NONE
337 }
317 }
338 );
318 );
319+
320+ assert_eq!(
321+ str::parse::<KeyEvent>("%").unwrap(),
322+ KeyEvent {
323+ code: KeyCode::Char('%'),
324+ modifiers: KeyModifiers::NONE
325+ }
326+ )
339 }
327 }
340
328
341 #[test]
329 #[test]
@@ -375,6 +363,16 @@ mod test {
375 assert!(str::parse::<KeyEvent>("FU").is_err());
363 assert!(str::parse::<KeyEvent>("FU").is_err());
376 assert!(str::parse::<KeyEvent>("123").is_err());
364 assert!(str::parse::<KeyEvent>("123").is_err());
377 assert!(str::parse::<KeyEvent>("S--").is_err());
365 assert!(str::parse::<KeyEvent>("S--").is_err());
366+ assert!(str::parse::<KeyEvent>("S-percent").is_err());
367+ }
368+
369+ #[test]
370+ fn parsing_unsupported_named_keys() {
371+ assert!(str::parse::<KeyEvent>("lt").is_err());
372+ assert!(str::parse::<KeyEvent>("gt").is_err());
373+ assert!(str::parse::<KeyEvent>("plus").is_err());
374+ assert!(str::parse::<KeyEvent>("percent").is_err());
375+ assert!(str::parse::<KeyEvent>("semicolon").is_err());
378 }
376 }
379
377
380 #[test]
378 #[test]