mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-07 02:57:34 +00:00
Don't insert input into editors when control or command keys are held
This is a follow-up to #475
This commit is contained in:
parent
a9cc8b46e4
commit
5c1aff1143
1 changed files with 20 additions and 13 deletions
|
@ -21,14 +21,19 @@ impl Event {
|
||||||
|
|
||||||
match event_type {
|
match event_type {
|
||||||
NSEventType::NSKeyDown => {
|
NSEventType::NSKeyDown => {
|
||||||
let mut input = None;
|
|
||||||
let modifiers = native_event.modifierFlags();
|
let modifiers = native_event.modifierFlags();
|
||||||
|
let ctrl = modifiers.contains(NSEventModifierFlags::NSControlKeyMask);
|
||||||
|
let alt = modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask);
|
||||||
|
let shift = modifiers.contains(NSEventModifierFlags::NSShiftKeyMask);
|
||||||
|
let cmd = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask);
|
||||||
|
|
||||||
let unmodified_chars = CStr::from_ptr(
|
let unmodified_chars = CStr::from_ptr(
|
||||||
native_event.charactersIgnoringModifiers().UTF8String() as *mut c_char,
|
native_event.charactersIgnoringModifiers().UTF8String() as *mut c_char,
|
||||||
)
|
)
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let mut input = None;
|
||||||
let unmodified_chars = if let Some(first_char) = unmodified_chars.chars().next() {
|
let unmodified_chars = if let Some(first_char) = unmodified_chars.chars().next() {
|
||||||
use cocoa::appkit::*;
|
use cocoa::appkit::*;
|
||||||
const BACKSPACE_KEY: u16 = 0x7f;
|
const BACKSPACE_KEY: u16 = 0x7f;
|
||||||
|
@ -71,6 +76,7 @@ impl Event {
|
||||||
NSF12FunctionKey => "f12",
|
NSF12FunctionKey => "f12",
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
if !cmd && !ctrl {
|
||||||
input = Some(
|
input = Some(
|
||||||
CStr::from_ptr(
|
CStr::from_ptr(
|
||||||
native_event.characters().UTF8String() as *mut c_char
|
native_event.characters().UTF8String() as *mut c_char
|
||||||
|
@ -79,6 +85,7 @@ impl Event {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
unmodified_chars
|
unmodified_chars
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,10 +95,10 @@ impl Event {
|
||||||
|
|
||||||
Some(Self::KeyDown {
|
Some(Self::KeyDown {
|
||||||
keystroke: Keystroke {
|
keystroke: Keystroke {
|
||||||
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
|
ctrl,
|
||||||
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
alt,
|
||||||
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
|
shift,
|
||||||
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
|
cmd,
|
||||||
key: unmodified_chars.into(),
|
key: unmodified_chars.into(),
|
||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
|
|
Loading…
Reference in a new issue