Skip to content

Commit

Permalink
add support to delete a char with Del
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Aug 22, 2023
1 parent 9c5f5d9 commit 2c21c3a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,24 @@ impl Editor {
}
}

fn delete_char_backward(&mut self) {
// NOTE: work on the chars and do not use remove which works on bytes
self.buffer = self
.buffer
.chars()
.take(self.cursor_position)
.chain(self.buffer.chars().skip(self.cursor_position + 1))
.collect();
}

/// TODO: documentation
pub(super) fn handle_key(&mut self, key: &Key) -> Option<(Mode, Option<Value>)> {
match key {
Key::ArrowLeft => self.move_cursor_left(),
Key::ArrowRight => self.move_cursor_right(),
Key::Char(c) => self.enter_char(*c),
Key::Backspace => self.delete_char(),
Key::Del => self.delete_char_backward(),
Key::Enter => {
let val = Value::String {
val: self.buffer.clone(),
Expand Down

0 comments on commit 2c21c3a

Please sign in to comment.