From 0b63d882ceeb47a395ecd3ff1c72a8e07dad5233 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 18 Nov 2021 14:23:36 -0800 Subject: [PATCH] Allow key bindings to F1 through F12 --- crates/gpui/src/platform/mac/event.rs | 46 ++++++++++++++++----------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/crates/gpui/src/platform/mac/event.rs b/crates/gpui/src/platform/mac/event.rs index 04712d599f..f205420dde 100644 --- a/crates/gpui/src/platform/mac/event.rs +++ b/crates/gpui/src/platform/mac/event.rs @@ -1,10 +1,4 @@ use crate::{geometry::vector::vec2f, keymap::Keystroke, platform::Event}; -use cocoa::appkit::{ - NSDeleteFunctionKey as DELETE_KEY, NSDownArrowFunctionKey as ARROW_DOWN_KEY, - NSLeftArrowFunctionKey as ARROW_LEFT_KEY, NSPageDownFunctionKey as PAGE_DOWN_KEY, - NSPageUpFunctionKey as PAGE_UP_KEY, NSRightArrowFunctionKey as ARROW_RIGHT_KEY, - NSUpArrowFunctionKey as ARROW_UP_KEY, -}; use cocoa::{ appkit::{NSEvent, NSEventModifierFlags, NSEventType}, base::{id, nil, YES}, @@ -12,11 +6,6 @@ use cocoa::{ }; use std::{ffi::CStr, os::raw::c_char}; -const BACKSPACE_KEY: u16 = 0x7f; -const ENTER_KEY: u16 = 0x0d; -const ESCAPE_KEY: u16 = 0x1b; -const TAB_KEY: u16 = 0x09; - impl Event { pub unsafe fn from_native(native_event: id, window_height: Option) -> Option { let event_type = native_event.eventType(); @@ -39,18 +28,39 @@ impl Event { .unwrap(); let unmodified_chars = if let Some(first_char) = unmodified_chars.chars().next() { + use cocoa::appkit::*; + const BACKSPACE_KEY: u16 = 0x7f; + const ENTER_KEY: u16 = 0x0d; + const ESCAPE_KEY: u16 = 0x1b; + const TAB_KEY: u16 = 0x09; + + #[allow(non_upper_case_globals)] match first_char as u16 { - ARROW_UP_KEY => "up", - ARROW_DOWN_KEY => "down", - ARROW_LEFT_KEY => "left", - ARROW_RIGHT_KEY => "right", - PAGE_UP_KEY => "pageup", - PAGE_DOWN_KEY => "pagedown", BACKSPACE_KEY => "backspace", ENTER_KEY => "enter", - DELETE_KEY => "delete", ESCAPE_KEY => "escape", TAB_KEY => "tab", + + NSUpArrowFunctionKey => "up", + NSDownArrowFunctionKey => "down", + NSLeftArrowFunctionKey => "left", + NSRightArrowFunctionKey => "right", + NSPageUpFunctionKey => "pageup", + NSPageDownFunctionKey => "pagedown", + NSDeleteFunctionKey => "delete", + NSF1FunctionKey => "f1", + NSF2FunctionKey => "f2", + NSF3FunctionKey => "f3", + NSF4FunctionKey => "f4", + NSF5FunctionKey => "f5", + NSF6FunctionKey => "f6", + NSF7FunctionKey => "f7", + NSF8FunctionKey => "f8", + NSF9FunctionKey => "f9", + NSF10FunctionKey => "f10", + NSF11FunctionKey => "f11", + NSF12FunctionKey => "f12", + _ => unmodified_chars, } } else {