Skip to content

Commit

Permalink
Add move-* commands support
Browse files Browse the repository at this point in the history
This implements the move_left/right/up/down commands.
The mappings are as suggested in issue xi-frontend#70:
  - `ml` / `move-left`
  - `mr` / `move-right`
  - `mu` / `move-up`
  - `md` / `move-down`
  • Loading branch information
JCavallo committed Jan 11, 2019
1 parent 29b01d2 commit 0375314
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand 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();

Expand Down
4 changes: 4 additions & 0 deletions src/core/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
24 changes: 24 additions & 0 deletions src/widgets/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions src/widgets/view/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 0375314

Please sign in to comment.