on master help sign in
simplify some keymap key names (#2677)
commit8351a82c2cae58dd49c654d0e878c9d7227ef9c8 authorHenry <correia.eh@gmail.com> dateSun 5 Jun 2022, 22:22 (4 years ago) parent0035c29
2 files changed+18−25
book/src/remapping.md−5 helix-view/src/input.rs+18−20
book/src/remapping.md−5
@@ -33,12 +33,7 @@ Control, Shift and Alt modifiers are encoded respectively with the prefixes
3333| Backspace | `"backspace"` |
3434| Space | `"space"` |
3535| Return/Enter | `"ret"` |
36−| < | `"lt"` |
37−| \> | `"gt"` |
38−| \+ | `"plus"` |
3936| \- | `"minus"` |
40−| ; | `"semicolon"` |
41−| % | `"percent"` |
4237| Left | `"left"` |
4338| Right | `"right"` |
4439| Up | `"up"` |
helix-view/src/input.rs+18−20
@@ -41,12 +41,7 @@ pub(crate) mod keys {
4141 pub(crate) const NULL: &str = "null";
4242 pub(crate) const ESC: &str = "esc";
4343 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";
4744 pub(crate) const MINUS: &str = "minus";
48− pub(crate) const SEMICOLON: &str = "semicolon";
49− pub(crate) const PERCENT: &str = "percent";
5045}
5146
5247impl fmt::Display for KeyEvent {
@@ -86,12 +81,7 @@ impl fmt::Display for KeyEvent {
8681 KeyCode::Null => f.write_str(keys::NULL)?,
8782 KeyCode::Esc => f.write_str(keys::ESC)?,
8883 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)?,
9284 KeyCode::Char('-') => f.write_str(keys::MINUS)?,
93− KeyCode::Char(';') => f.write_str(keys::SEMICOLON)?,
94− KeyCode::Char('%') => f.write_str(keys::PERCENT)?,
9585 KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?,
9686 KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?,
9787 };
@@ -119,12 +109,7 @@ impl UnicodeWidthStr for KeyEvent {
119109 KeyCode::Null => keys::NULL.len(),
120110 KeyCode::Esc => keys::ESC.len(),
121111 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(),
125112 KeyCode::Char('-') => keys::MINUS.len(),
126− KeyCode::Char(';') => keys::SEMICOLON.len(),
127− KeyCode::Char('%') => keys::PERCENT.len(),
128113 KeyCode::F(1..=9) => 2,
129114 KeyCode::F(_) => 3,
130115 KeyCode::Char(c) => c.width().unwrap_or(0),
@@ -168,12 +153,7 @@ impl std::str::FromStr for KeyEvent {
168153 keys::NULL => KeyCode::Null,
169154 keys::ESC => KeyCode::Esc,
170155 keys::SPACE => KeyCode::Char(' '),
171− keys::LESS_THAN => KeyCode::Char('<'),
172− keys::GREATER_THAN => KeyCode::Char('>'),
173− keys::PLUS => KeyCode::Char('+'),
174156 keys::MINUS => KeyCode::Char('-'),
175− keys::SEMICOLON => KeyCode::Char(';'),
176− keys::PERCENT => KeyCode::Char('%'),
177157 single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()),
178158 function if function.len() > 1 && function.starts_with('F') => {
179159 let function: String = function.chars().skip(1).collect();
@@ -336,6 +316,14 @@ mod test {
336316 modifiers: KeyModifiers::NONE
337317 }
338318 );
319+
320+ assert_eq!(
321+ str::parse::<KeyEvent>("%").unwrap(),
322+ KeyEvent {
323+ code: KeyCode::Char('%'),
324+ modifiers: KeyModifiers::NONE
325+ }
326+ )
339327 }
340328
341329 #[test]
@@ -375,6 +363,16 @@ mod test {
375363 assert!(str::parse::<KeyEvent>("FU").is_err());
376364 assert!(str::parse::<KeyEvent>("123").is_err());
377365 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());
378376 }
379377
380378 #[test]