From 1d9ce94f968440e2ca7867406e803c2a18662da4 Mon Sep 17 00:00:00 2001 From: Patrick Decat Date: Sat, 3 Dec 2022 11:51:15 +0100 Subject: [PATCH] Add support for some additional keys in interactive mode (#634) * Ignore tab key in interactive mode * Support home and end keys in interactive mode * Support delete key in interactive mode --- src/command/client/search/cursor.rs | 10 +++++++--- src/command/client/search/interactive.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/command/client/search/cursor.rs b/src/command/client/search/cursor.rs index da2be45..827242c 100644 --- a/src/command/client/search/cursor.rs +++ b/src/command/client/search/cursor.rs @@ -57,13 +57,17 @@ impl Cursor { self.index += c.len_utf8(); } - pub fn remove(&mut self) -> char { - self.source.remove(self.index) + pub fn remove(&mut self) -> Option { + if self.index < self.source.len() { + Some(self.source.remove(self.index)) + } else { + None + } } pub fn back(&mut self) -> Option { if self.left() { - Some(self.remove()) + self.remove() } else { None } diff --git a/src/command/client/search/interactive.rs b/src/command/client/search/interactive.rs index 36497db..e23b7c6 100644 --- a/src/command/client/search/interactive.rs +++ b/src/command/client/search/interactive.rs @@ -69,6 +69,7 @@ impl State { len: usize, ) -> Option { match input { + TermEvent::Key(Key::Char('\t')) => {} TermEvent::Key(Key::Ctrl('c' | 'd' | 'g')) => return Some(RETURN_ORIGINAL), TermEvent::Key(Key::Esc) => { return Some(match settings.exit_mode { @@ -87,12 +88,15 @@ impl State { self.input.left(); } TermEvent::Key(Key::Right | Key::Ctrl('l')) => self.input.right(), - TermEvent::Key(Key::Ctrl('a')) => self.input.start(), - TermEvent::Key(Key::Ctrl('e')) => self.input.end(), + TermEvent::Key(Key::Ctrl('a') | Key::Home) => self.input.start(), + TermEvent::Key(Key::Ctrl('e') | Key::End) => self.input.end(), TermEvent::Key(Key::Char(c)) => self.input.insert(*c), TermEvent::Key(Key::Backspace) => { self.input.back(); } + TermEvent::Key(Key::Delete) => { + self.input.remove(); + } TermEvent::Key(Key::Ctrl('w')) => { // remove the first batch of whitespace while matches!(self.input.back(), Some(c) if c.is_whitespace()) {}