From ca66dd8ef9e3e9d94e1f1099081b3e33c2f5ede9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Macio=C5=82ek?= Date: Fri, 21 Jun 2024 22:22:42 +0200 Subject: [PATCH] key shortcuts p2 --- src/app.rs | 18 ++++++++++++++++++ src/handler.rs | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) 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 {