Skip to content

Commit

Permalink
Support delete key in interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed Dec 3, 2022
1 parent 0900e26 commit 9b00822
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/command/client/search/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
if self.index < self.source.len() {
Some(self.source.remove(self.index))
} else {
None
}
}

pub fn back(&mut self) -> Option<char> {
if self.left() {
Some(self.remove())
self.remove()
} else {
None
}
Expand Down
3 changes: 3 additions & 0 deletions src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ impl State {
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()) {}
Expand Down

0 comments on commit 9b00822

Please sign in to comment.