From 03753145780feb4227b92d957e96e558c99b7e97 Mon Sep 17 00:00:00 2001 From: Jean Cavallo Date: Fri, 11 Jan 2019 16:39:51 +0100 Subject: [PATCH] Add move-* commands support This implements the move_left/right/up/down commands. The mappings are as suggested in issue #70: - `ml` / `move-left` - `mr` / `move-right` - `mu` / `move-up` - `md` / `move-down` --- src/core/cmd.rs | 12 ++++++++++++ src/core/tui.rs | 4 ++++ src/widgets/editor.rs | 24 ++++++++++++++++++++++++ src/widgets/view/view.rs | 16 ++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/src/core/cmd.rs b/src/core/cmd.rs index 37d9471..222b3e1 100644 --- a/src/core/cmd.rs +++ b/src/core/cmd.rs @@ -24,6 +24,14 @@ pub enum Command { NextBuffer, /// Cycle to the previous buffer. PrevBuffer, + /// Move cursor left. + MoveLeft, + /// Move cursor right. + MoveRight, + /// Move cursor up. + MoveUp, + /// Move cursor down. + MoveDown, /// Page down PageDown, /// Page up @@ -57,6 +65,10 @@ impl FromStr for Command { "bp" | "prev-buffer" =>Ok(Command::PrevBuffer), "pd" | "page-down" => Ok(Command::PageDown), "pu" | "page-up" => Ok(Command::PageUp), + "ml" | "move-left" => Ok(Command::MoveLeft), + "mr" | "move-right" => Ok(Command::MoveRight), + "mu" | "move-up" => Ok(Command::MoveUp), + "md" | "move-down" => Ok(Command::MoveDown), command => { let mut parts: Vec<&str> = command.split(' ').collect(); diff --git a/src/core/tui.rs b/src/core/tui.rs index 224032a..971919a 100644 --- a/src/core/tui.rs +++ b/src/core/tui.rs @@ -65,6 +65,10 @@ impl Tui { Command::SetTheme(theme) => self.editor.set_theme(&theme), Command::NextBuffer => self.editor.next_buffer(), Command::PrevBuffer => self.editor.prev_buffer(), + Command::MoveLeft => self.editor.move_left(), + Command::MoveRight => self.editor.move_right(), + Command::MoveUp => self.editor.move_up(), + Command::MoveDown => self.editor.move_down(), Command::PageDown => self.editor.page_down(), Command::PageUp => self.editor.page_up(), } diff --git a/src/widgets/editor.rs b/src/widgets/editor.rs index ab0568f..1c273be 100644 --- a/src/widgets/editor.rs +++ b/src/widgets/editor.rs @@ -170,6 +170,30 @@ impl Editor { } } + pub fn move_left(&mut self) { + if let Some(view) = self.views.get_mut(&self.current_view) { + view.move_left(); + } + } + + pub fn move_right(&mut self) { + if let Some(view) = self.views.get_mut(&self.current_view) { + view.move_right(); + } + } + + pub fn move_up(&mut self) { + if let Some(view) = self.views.get_mut(&self.current_view) { + view.move_up(); + } + } + + pub fn move_down(&mut self) { + if let Some(view) = self.views.get_mut(&self.current_view) { + view.move_down(); + } + } + pub fn page_down(&mut self) { if let Some(view) = self.views.get_mut(&self.current_view) { view.page_down(); diff --git a/src/widgets/view/view.rs b/src/widgets/view/view.rs index 8f404d9..6460ead 100644 --- a/src/widgets/view/view.rs +++ b/src/widgets/view/view.rs @@ -106,6 +106,22 @@ impl View { self.client.page_up() } + pub fn move_left(&mut self) { + self.client.left() + } + + pub fn move_right(&mut self) { + self.client.right() + } + + pub fn move_up(&mut self) { + self.client.up() + } + + pub fn move_down(&mut self) { + self.client.down() + } + fn update_window(&mut self) { if self.cursor.line < self.cache.before() { error!(