Skip to content

Commit

Permalink
fix(accelerator): add missing KeyCode to prevent `no key equivalent f…
Browse files Browse the repository at this point in the history
…or Accelerator` (#148)

* add missing keycode to prevent `no key equivalent for Accelerator`

* add escape and fix modifiers mask

* cleanup

* make clippy happy

* add `Escape` in changelog
  • Loading branch information
lemarier committed Jul 21, 2021
1 parent 6e72e54 commit ecd3c40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/macos-accelerator-spacebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Fix `no key equivalent for Accelerator` for `Space`, `Escape`, `Minus` and `Equal` keycode.
11 changes: 8 additions & 3 deletions src/platform_impl/macos/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ fn make_menu_item_from_alloc(
// allocate our item to our class
let item: id =
msg_send![alloc, initWithTitle: title action: selector keyEquivalent: key_equivalent];
if let Some(masks) = accelerator.map(Accelerator::key_modifier_mask) {
item.setKeyEquivalentModifierMask_(masks)
}

let mask = accelerator
.map(Accelerator::key_modifier_mask)
.unwrap_or_else(NSEventModifierFlags::empty);
item.setKeyEquivalentModifierMask_(mask);
item
}
}
Expand Down Expand Up @@ -468,6 +469,8 @@ impl Accelerator {
/// Returns the empty string if no key equivalent is known.
fn key_equivalent(self) -> String {
match self.key {
KeyCode::Minus => "-".into(),
KeyCode::Equal => "=".into(),
KeyCode::KeyA => "a".into(),
KeyCode::KeyB => "b".into(),
KeyCode::KeyC => "c".into(),
Expand Down Expand Up @@ -504,6 +507,8 @@ impl Accelerator {
KeyCode::Digit7 => "7".into(),
KeyCode::Digit8 => "8".into(),
KeyCode::Digit9 => "9".into(),
KeyCode::Escape => "\u{1b}".into(),
KeyCode::Space => "\u{0020}".into(),
// from NSText.h
KeyCode::Enter => "\u{0003}".into(),
KeyCode::Backspace => "\u{0008}".into(),
Expand Down

0 comments on commit ecd3c40

Please sign in to comment.