Merge pull request #129 from snaggen/special_case_ctrl_keys

Add exceptions for certain keys to avoid double keys being sent
This commit is contained in:
Jeremy Soller 2024-02-08 13:54:56 -07:00 committed by GitHub
commit cc9368c2e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -655,14 +655,15 @@ where
//Special handle Enter, Escape, Backspace and Tab as described in
//https://sw.kovidgoyal.net/kitty/keyboard-protocol/#legacy-key-event-encoding
//Also special handle Ctrl-_ to behave like xterm
//Let CharacterRecieved event handle Ctrl keys if possible
let alt_prefix = if modifiers.alt() { "\x1B" } else { "" };
match key_code {
KeyCode::Enter => {
KeyCode::Enter if !modifiers.control() => {
terminal
.input_scroll(format!("{}{}", alt_prefix, "\x0D").as_bytes().to_vec());
status = Status::Captured;
}
KeyCode::Escape => {
KeyCode::Escape if !modifiers.control() => {
//Escape with any modifier will cancel selection
let had_selection = {
let mut term = terminal.term.lock();
@ -677,8 +678,8 @@ where
}
status = Status::Captured;
}
KeyCode::Backspace => {
let code = if modifiers.control() { "\x08" } else { "\x7f" };
KeyCode::Backspace if !modifiers.control() => {
let code = "\x7f";
terminal
.input_scroll(format!("{}{}", alt_prefix, code).as_bytes().to_vec());
status = Status::Captured;
@ -700,6 +701,11 @@ where
state.modifiers = modifiers;
}
Event::Keyboard(KeyEvent::CharacterReceived(character)) if state.is_focused => {
//Tab and Delete is handled by the KeyPress event
if character as u32 == 9 || character as u32 == 127 {
return status;
}
match (
state.modifiers.logo(),
state.modifiers.control(),