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
This commit is contained in:
parent
478af1fa0f
commit
1d9ce94f96
2 changed files with 13 additions and 5 deletions
|
@ -57,13 +57,17 @@ impl Cursor {
|
||||||
self.index += c.len_utf8();
|
self.index += c.len_utf8();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self) -> char {
|
pub fn remove(&mut self) -> Option<char> {
|
||||||
self.source.remove(self.index)
|
if self.index < self.source.len() {
|
||||||
|
Some(self.source.remove(self.index))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn back(&mut self) -> Option<char> {
|
pub fn back(&mut self) -> Option<char> {
|
||||||
if self.left() {
|
if self.left() {
|
||||||
Some(self.remove())
|
self.remove()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ impl State {
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Option<usize> {
|
) -> Option<usize> {
|
||||||
match input {
|
match input {
|
||||||
|
TermEvent::Key(Key::Char('\t')) => {}
|
||||||
TermEvent::Key(Key::Ctrl('c' | 'd' | 'g')) => return Some(RETURN_ORIGINAL),
|
TermEvent::Key(Key::Ctrl('c' | 'd' | 'g')) => return Some(RETURN_ORIGINAL),
|
||||||
TermEvent::Key(Key::Esc) => {
|
TermEvent::Key(Key::Esc) => {
|
||||||
return Some(match settings.exit_mode {
|
return Some(match settings.exit_mode {
|
||||||
|
@ -87,12 +88,15 @@ impl State {
|
||||||
self.input.left();
|
self.input.left();
|
||||||
}
|
}
|
||||||
TermEvent::Key(Key::Right | Key::Ctrl('l')) => self.input.right(),
|
TermEvent::Key(Key::Right | Key::Ctrl('l')) => self.input.right(),
|
||||||
TermEvent::Key(Key::Ctrl('a')) => self.input.start(),
|
TermEvent::Key(Key::Ctrl('a') | Key::Home) => self.input.start(),
|
||||||
TermEvent::Key(Key::Ctrl('e')) => self.input.end(),
|
TermEvent::Key(Key::Ctrl('e') | Key::End) => self.input.end(),
|
||||||
TermEvent::Key(Key::Char(c)) => self.input.insert(*c),
|
TermEvent::Key(Key::Char(c)) => self.input.insert(*c),
|
||||||
TermEvent::Key(Key::Backspace) => {
|
TermEvent::Key(Key::Backspace) => {
|
||||||
self.input.back();
|
self.input.back();
|
||||||
}
|
}
|
||||||
|
TermEvent::Key(Key::Delete) => {
|
||||||
|
self.input.remove();
|
||||||
|
}
|
||||||
TermEvent::Key(Key::Ctrl('w')) => {
|
TermEvent::Key(Key::Ctrl('w')) => {
|
||||||
// remove the first batch of whitespace
|
// remove the first batch of whitespace
|
||||||
while matches!(self.input.back(), Some(c) if c.is_whitespace()) {}
|
while matches!(self.input.back(), Some(c) if c.is_whitespace()) {}
|
||||||
|
|
Loading…
Reference in a new issue