From 86baa4104aae23090a793772c9917e7ee7076f00 Mon Sep 17 00:00:00 2001 From: fengqi <362254883@qq.com> Date: Tue, 2 Jul 2024 12:11:48 +0800 Subject: [PATCH 1/2] 1. terminal: added support for Alt+ character input --- lapce-app/src/terminal/data.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lapce-app/src/terminal/data.rs b/lapce-app/src/terminal/data.rs index 5e49b0c322..26da96d8fe 100644 --- a/lapce-app/src/terminal/data.rs +++ b/lapce-app/src/terminal/data.rs @@ -429,14 +429,14 @@ impl TerminalData { pub fn send_keypress(&self, key: &KeyEvent) -> bool { if let Some(command) = Self::resolve_key_event(key) { - self.receive_char(command); + self.receive_char(command.as_str()); true } else { false } } - pub fn resolve_key_event(key: &KeyEvent) -> Option<&str> { + pub fn resolve_key_event(key: &KeyEvent) -> Option { let key = key.clone(); // Generates a `Modifiers` value to check against. @@ -505,13 +505,13 @@ impl TerminalData { // No modifiers ([], $evt:ident, $no_mod:literal) => { if $evt.modifiers.is_empty() { - return Some($no_mod); + return Some($no_mod.to_string()); } }; // A single modifier combination ([$($mod:ident)|+], $evt:ident, $pre:literal, $post:literal) => { if $evt.modifiers == modifiers!($($mod)|+) { - return Some(concat!($pre, modval!($($mod)|+), $post)); + return Some(concat!($pre, modval!($($mod)|+), $post).to_string()); } }; // Break down multiple modifiers into a series of single combination branches @@ -563,24 +563,28 @@ impl TerminalData { _ => return None, }; - Some(str) + Some(str.to_string()) + } else if key.modifiers == Modifiers::ALT { + let mut rs = String::from('\x1b'); + rs.push_str(c.as_str()); + Some(rs) } else { None } } Key::Named(NamedKey::Backspace) => { Some(if key.modifiers.control() { - "\x08" // backspace + "\x08".to_string() // backspace } else if key.modifiers.alt() { - "\x1b\x7f" + "\x1b\x7f".to_string() } else { - "\x7f" + "\x7f".to_string() }) } - Key::Named(NamedKey::Tab) => Some("\x09"), - Key::Named(NamedKey::Enter) => Some("\r"), - Key::Named(NamedKey::Escape) => Some("\x1b"), + Key::Named(NamedKey::Tab) => Some("\x09".to_string()), + Key::Named(NamedKey::Enter) => Some("\r".to_string()), + Key::Named(NamedKey::Escape) => Some("\x1b".to_string()), // The following either expands to `\x1b[X` or `\x1b[1;NX` where N is a modifier value Key::Named(NamedKey::ArrowUp) => { From a67271118a804cf8f411d87bf19d0c412c024ae7 Mon Sep 17 00:00:00 2001 From: fengqi <362254883@qq.com> Date: Tue, 2 Jul 2024 18:08:59 +0800 Subject: [PATCH 2/2] 1. terminal: added support for Alt+ some character input --- lapce-app/src/terminal/data.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lapce-app/src/terminal/data.rs b/lapce-app/src/terminal/data.rs index 26da96d8fe..9a254e408f 100644 --- a/lapce-app/src/terminal/data.rs +++ b/lapce-app/src/terminal/data.rs @@ -429,14 +429,14 @@ impl TerminalData { pub fn send_keypress(&self, key: &KeyEvent) -> bool { if let Some(command) = Self::resolve_key_event(key) { - self.receive_char(command.as_str()); + self.receive_char(command); true } else { false } } - pub fn resolve_key_event(key: &KeyEvent) -> Option { + pub fn resolve_key_event(key: &KeyEvent) -> Option<&str> { let key = key.clone(); // Generates a `Modifiers` value to check against. @@ -505,13 +505,13 @@ impl TerminalData { // No modifiers ([], $evt:ident, $no_mod:literal) => { if $evt.modifiers.is_empty() { - return Some($no_mod.to_string()); + return Some($no_mod); } }; // A single modifier combination ([$($mod:ident)|+], $evt:ident, $pre:literal, $post:literal) => { if $evt.modifiers == modifiers!($($mod)|+) { - return Some(concat!($pre, modval!($($mod)|+), $post).to_string()); + return Some(concat!($pre, modval!($($mod)|+), $post)); } }; // Break down multiple modifiers into a series of single combination branches @@ -563,28 +563,33 @@ impl TerminalData { _ => return None, }; - Some(str.to_string()) + Some(str) } else if key.modifiers == Modifiers::ALT { - let mut rs = String::from('\x1b'); - rs.push_str(c.as_str()); - Some(rs) + let str = match c.as_str() { + "," => "\x1b\x2c", + "." => "\x1b\x2e", + "/" => "\x1b\x2f", + "\\" => "\x1b\x5c", + _ => return None, + }; + Some(str) } else { None } } Key::Named(NamedKey::Backspace) => { Some(if key.modifiers.control() { - "\x08".to_string() // backspace + "\x08" // backspace } else if key.modifiers.alt() { - "\x1b\x7f".to_string() + "\x1b\x7f" } else { - "\x7f".to_string() + "\x7f" }) } - Key::Named(NamedKey::Tab) => Some("\x09".to_string()), - Key::Named(NamedKey::Enter) => Some("\r".to_string()), - Key::Named(NamedKey::Escape) => Some("\x1b".to_string()), + Key::Named(NamedKey::Tab) => Some("\x09"), + Key::Named(NamedKey::Enter) => Some("\r"), + Key::Named(NamedKey::Escape) => Some("\x1b"), // The following either expands to `\x1b[X` or `\x1b[1;NX` where N is a modifier value Key::Named(NamedKey::ArrowUp) => {