Implement Home/End

This commit is contained in:
Jeremy Soller 2022-10-19 11:08:15 -06:00
parent 369c265646
commit c29eed3a94
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
3 changed files with 27 additions and 0 deletions

View file

@ -239,6 +239,14 @@ where
buffer.action(TextAction::Delete);
return Status::Captured;
},
KeyCode::Home => {
buffer.action(TextAction::Home);
return Status::Captured;
},
KeyCode::End => {
buffer.action(TextAction::End);
return Status::Captured;
},
KeyCode::PageUp => {
buffer.action(TextAction::PageUp);
return Status::Captured;

View file

@ -166,6 +166,8 @@ fn main() {
orbclient::K_DOWN if event.pressed => buffer.action(TextAction::Down),
orbclient::K_BKSP if event.pressed => buffer.action(TextAction::Backspace),
orbclient::K_DEL if event.pressed => buffer.action(TextAction::Delete),
orbclient::K_HOME if event.pressed => buffer.action(TextAction::Home),
orbclient::K_END if event.pressed => buffer.action(TextAction::End),
orbclient::K_PGUP if event.pressed => buffer.action(TextAction::PageUp),
orbclient::K_PGDN if event.pressed => buffer.action(TextAction::PageDown),
orbclient::K_0 if event.pressed && ctrl_pressed => {

View file

@ -21,6 +21,10 @@ pub enum TextAction {
Backspace,
/// Delete text in front of cursor
Delete,
/// Move cursor to start of line
Home,
/// Move cursor to end of line
End,
/// Scroll up one page
PageUp,
/// Scroll down one page
@ -382,6 +386,19 @@ impl<'a> TextBuffer<'a> {
self.reshape_line(line.line_i);
}
},
TextAction::Home => {
if self.cursor.glyph > 0 {
self.cursor.glyph = 0;
self.redraw = true;
}
},
TextAction::End => {
let line = &self.layout_lines[self.cursor.line];
if self.cursor.glyph < line.glyphs.len() {
self.cursor.glyph = line.glyphs.len();
self.redraw = true;
}
}
TextAction::PageUp => {
self.scroll -= self.lines();
self.redraw = true;