diff --git a/src/app.rs b/src/app.rs index 39a7294..5f41627 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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; + } } diff --git a/src/handler.rs b/src/handler.rs index 2a28af4..6c67907 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -3,7 +3,7 @@ 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(); } @@ -11,10 +11,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { 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 {