Skip to content

Commit

Permalink
cursor x movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed May 7, 2024
1 parent 93586a2 commit 0064758
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ impl App {
self.cursor_position.x = previous_char;
}
}

pub fn move_cursor(&mut self, direction: i8) {
if direction < 0 {
if let Some(previous_char) = self.cursor_position.x.checked_sub(1) {
self.cursor_position.x = previous_char;
}
} else {
self.cursor_position.x += 1;
}
}
}
6 changes: 6 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
KeyCode::Backspace => {
app.pop_char();
}
KeyCode::Left => {
app.move_cursor(-1);
}
KeyCode::Right => {
app.move_cursor(1);
}
_ => {
if let KeyCode::Char(c) = key_event.code {
app.append_char(c)
Expand Down

0 comments on commit 0064758

Please sign in to comment.