backspace & delete
This commit is contained in:
parent
cb4a43d00c
commit
c112195b9d
1 changed files with 18 additions and 2 deletions
|
@ -57,6 +57,8 @@ impl Editor {
|
||||||
match key {
|
match key {
|
||||||
Key::Esc => self.quit = true,
|
Key::Esc => self.quit = true,
|
||||||
Key::Char(char) => self.insert_char(char),
|
Key::Char(char) => self.insert_char(char),
|
||||||
|
Key::Backspace => self.backspace(),
|
||||||
|
Key::Delete => self.delete(),
|
||||||
Key::Left => self.move_left(),
|
Key::Left => self.move_left(),
|
||||||
Key::Right => self.move_right(),
|
Key::Right => self.move_right(),
|
||||||
Key::Up => self.move_up(),
|
Key::Up => self.move_up(),
|
||||||
|
@ -134,9 +136,23 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_char(&mut self, ch: char) {
|
fn insert_char(&mut self, ch: char) {
|
||||||
let index = self.current_line().start + self.cursor.column;
|
self.text.insert(self.index(), ch);
|
||||||
self.text.insert(index, ch);
|
self.find_lines();
|
||||||
self.move_right();
|
self.move_right();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn backspace(&mut self) {
|
||||||
|
self.text.remove(self.index() - 1);
|
||||||
|
self.find_lines();
|
||||||
|
self.move_left();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete(&mut self) {
|
||||||
|
self.text.remove(self.index());
|
||||||
self.find_lines();
|
self.find_lines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn index(&self) -> usize {
|
||||||
|
self.current_line().start + self.cursor.column
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue