mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 13:21:38 +03:00
win32 input mode: fixup ctrl-ascii key combinations
refs: https://github.com/microsoft/terminal/issues/13134 refs: https://github.com/wez/wezterm/issues/1904 refs: https://github.com/wez/wezterm/issues/1509 refs: https://github.com/wez/wezterm/issues/2009
This commit is contained in:
parent
89e88c876d
commit
578fa92a2e
@ -538,6 +538,9 @@ fn is_ambiguous_ascii_ctrl(c: char) -> bool {
|
||||
/// produced in combination with SHIFT) that may not be 100%
|
||||
/// the right thing to do here for users with non-US layouts.
|
||||
fn ctrl_mapping(c: char) -> Option<char> {
|
||||
// Please also sync with the copy of this function that
|
||||
// lives in wezterm-input-types :-/
|
||||
// FIXME: move this to wezterm-input-types and take a dep on it?
|
||||
Some(match c {
|
||||
'@' | '`' | ' ' | '2' => '\x00',
|
||||
'A' | 'a' => '\x01',
|
||||
|
@ -1181,7 +1181,16 @@ impl KeyEvent {
|
||||
match &self.key {
|
||||
KeyCode::Composed(_) => None,
|
||||
KeyCode::Char(c) => {
|
||||
let uni = *c as u32;
|
||||
let c = if self.modifiers.contains(Modifiers::CTRL) {
|
||||
// Ensure that we rewrite the unicode value to the ASCII CTRL
|
||||
// equivalent value.
|
||||
// <https://github.com/microsoft/terminal/issues/13134>
|
||||
ctrl_mapping(*c).unwrap_or(*c)
|
||||
} else {
|
||||
*c
|
||||
};
|
||||
let uni = c as u32;
|
||||
|
||||
Some(format!(
|
||||
"\u{1b}[{};{};{};{};{};{}_",
|
||||
vkey, scan_code, uni, key_down, control_key_state, self.repeat_count
|
||||
@ -1234,3 +1243,52 @@ impl Default for WindowDecorations {
|
||||
WindowDecorations::TITLE | WindowDecorations::RESIZE
|
||||
}
|
||||
}
|
||||
|
||||
/// Map c to its Ctrl equivalent.
|
||||
/// In theory, this mapping is simply translating alpha characters
|
||||
/// to upper case and then masking them by 0x1f, but xterm inherits
|
||||
/// some built-in translation from legacy X11 so that are some
|
||||
/// aliased mappings and a couple that might be technically tied
|
||||
/// to US keyboard layout (particularly the punctuation characters
|
||||
/// produced in combination with SHIFT) that may not be 100%
|
||||
/// the right thing to do here for users with non-US layouts.
|
||||
fn ctrl_mapping(c: char) -> Option<char> {
|
||||
// Please also sync with the copy of this function that
|
||||
// lives in termwiz :-/
|
||||
Some(match c {
|
||||
'@' | '`' | ' ' | '2' => '\x00',
|
||||
'A' | 'a' => '\x01',
|
||||
'B' | 'b' => '\x02',
|
||||
'C' | 'c' => '\x03',
|
||||
'D' | 'd' => '\x04',
|
||||
'E' | 'e' => '\x05',
|
||||
'F' | 'f' => '\x06',
|
||||
'G' | 'g' => '\x07',
|
||||
'H' | 'h' => '\x08',
|
||||
'I' | 'i' => '\x09',
|
||||
'J' | 'j' => '\x0a',
|
||||
'K' | 'k' => '\x0b',
|
||||
'L' | 'l' => '\x0c',
|
||||
'M' | 'm' => '\x0d',
|
||||
'N' | 'n' => '\x0e',
|
||||
'O' | 'o' => '\x0f',
|
||||
'P' | 'p' => '\x10',
|
||||
'Q' | 'q' => '\x11',
|
||||
'R' | 'r' => '\x12',
|
||||
'S' | 's' => '\x13',
|
||||
'T' | 't' => '\x14',
|
||||
'U' | 'u' => '\x15',
|
||||
'V' | 'v' => '\x16',
|
||||
'W' | 'w' => '\x17',
|
||||
'X' | 'x' => '\x18',
|
||||
'Y' | 'y' => '\x19',
|
||||
'Z' | 'z' => '\x1a',
|
||||
'[' | '3' | '{' => '\x1b',
|
||||
'\\' | '4' | '|' => '\x1c',
|
||||
']' | '5' | '}' => '\x1d',
|
||||
'^' | '6' | '~' => '\x1e',
|
||||
'_' | '7' | '/' => '\x1f',
|
||||
'8' | '?' => '\x7f', // `Delete`
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user