Skip to content

Commit

Permalink
fix: parse Arrow* in a accelerator string (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Oct 31, 2022
1 parent c02aee8 commit 5e85dbe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/accelerator-arrowup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

Add support for parsing `ArrowUp`, `ArrowDown`, `ArrowLeft` and `ArrowRight` in a str as valid key. Previously only `Up`, `Down`, `Left` and `Right` worked.
6 changes: 3 additions & 3 deletions src/accelerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fn parse_accelerator(accelerator_string: &str) -> Result<Accelerator, Accelerato
let mut mods = ModifiersState::empty();
let mut key = KeyCode::Unidentified(NativeKeyCode::Unidentified);

for raw in accelerator_string.to_uppercase().split('+') {
for raw in accelerator_string.split('+') {
let token = raw.trim().to_string();
if token.is_empty() {
return Err(AcceleratorParseError(
Expand All @@ -330,7 +330,7 @@ fn parse_accelerator(accelerator_string: &str) -> Result<Accelerator, Accelerato
)));
}

match token.as_str() {
match token.to_uppercase().as_str() {
"OPTION" | "ALT" => {
mods.set(ModifiersState::ALT, true);
}
Expand All @@ -350,7 +350,7 @@ fn parse_accelerator(accelerator_string: &str) -> Result<Accelerator, Accelerato
mods.set(ModifiersState::CONTROL, true);
}
_ => {
if let Ok(keycode) = KeyCode::from_str(token.to_uppercase().as_str()) {
if let Ok(keycode) = KeyCode::from_str(&token) {
match keycode {
KeyCode::Unidentified(_) => {
return Err(AcceleratorParseError(format!(
Expand Down
8 changes: 4 additions & 4 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,10 @@ impl FromStr for KeyCode {
"PAGEDOWN" => KeyCode::PageDown,
"PAGEUP" => KeyCode::PageUp,

"DOWN" => KeyCode::ArrowDown,
"UP" => KeyCode::ArrowUp,
"LEFT" => KeyCode::ArrowLeft,
"RIGHT" => KeyCode::ArrowRight,
"DOWN" | "ARROWDOWN" => KeyCode::ArrowDown,
"UP" | "ARROWUP" => KeyCode::ArrowUp,
"LEFT" | "ARROWLEFT" => KeyCode::ArrowLeft,
"RIGHT" | "ARROWRIGHT" => KeyCode::ArrowRight,

"NUMLOCK" => KeyCode::NumLock,
"NUMADD" | "NUMPADADD" => KeyCode::NumpadAdd,
Expand Down

0 comments on commit 5e85dbe

Please sign in to comment.