feat(editor): support PageUp, PageDown, Home and End

This commit is contained in:
Harsh Shandilya 2022-08-07 22:27:12 +05:30
parent aff2d24d33
commit a7d8164200
No known key found for this signature in database
GPG Key ID: 366D7BBAD1031E80

View File

@ -47,7 +47,14 @@ impl Editor {
let pressed_key = Terminal::read_key()?;
match pressed_key {
Key::Ctrl('q') => self.should_quit = true,
Key::Up | Key::Left | Key::Right | Key::Down => self.move_cursor(pressed_key),
Key::Up
| Key::Left
| Key::Right
| Key::Down
| Key::PageUp
| Key::PageDown
| Key::Home
| Key::End => self.move_cursor(pressed_key),
_ => (),
};
Ok(())
@ -108,6 +115,10 @@ impl Editor {
x = x.saturating_add(1);
}
}
Key::PageUp => y = 0,
Key::PageDown => y = height,
Key::Home => x = 0,
Key::End => x = width,
_ => (),
}
self.cursor_position = Position { x, y }