Skip to content

Commit

Permalink
key shortcuts p2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Jun 21, 2024
1 parent 1e5acf1 commit ca66dd8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,22 @@ impl App {
self.cursor_offset.x = 0;
}
}

pub fn jump_at_end_line(&mut self) {
let pos = self.get_cursor_position();
let len = self.content[pos.y].len();
let width = self.window_size.width.into();

if len > width {
self.cursor_position.x = width;
self.cursor_offset.x = len - width;
} else {
self.cursor_position.x = len - self.cursor_offset.x;
}
}

pub fn jump_at_start_line(&mut self) {
self.cursor_position.x = 0;
self.cursor_offset.x = 0;
}
}
6 changes: 3 additions & 3 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};

pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
match key_event.modifiers {
KeyModifiers::CONTROL => {
KeyModifiers::CONTROL || KeyModifiers::ALT => {
if key_event.code == KeyCode::Char('c') || key_event.code == KeyCode::Char('C') {
app.quit();
}
if key_event.code == KeyCode::Char('s') || key_event.code == KeyCode::Char('S') {
app.save_to_file();
}
if key_event.code == KeyCode::Left {
// TODO: handling
app.jump_at_start_line();
}
if key_event.code == KeyCode::Right {
// TODO: handling
app.jump_at_end_line();
}
}
_ => match key_event.code {
Expand Down

0 comments on commit ca66dd8

Please sign in to comment.