From 5382ce7408b8bce8408ae07c9d53da5a43843ed1 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Thu, 30 Apr 2020 11:52:11 +0200 Subject: [PATCH] Improve navigation (#29) * offer commit only when selecting staging area * show quickbar cmd to switch between unstaged/staged * adjust size of focused file tree --- src/app.rs | 55 ++++++++++++++++++++++++++++++++++++---- src/components/commit.rs | 20 --------------- src/strings.rs | 12 +++++++++ 3 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/app.rs b/src/app.rs index ce07f7fa..f1dbdac2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -138,10 +138,17 @@ impl App { let left_chunks = Layout::default() .direction(Direction::Vertical) .constraints( - [ - Constraint::Percentage(50), - Constraint::Percentage(50), - ] + if self.diff_target == DiffTarget::WorkingDir { + [ + Constraint::Percentage(60), + Constraint::Percentage(40), + ] + } else { + [ + Constraint::Percentage(40), + Constraint::Percentage(60), + ] + } .as_ref(), ) .split(chunks[0]); @@ -187,6 +194,13 @@ impl App { DiffTarget::WorkingDir => Focus::WorkDir, }) } + keys::OPEN_COMMIT + if !self.index.is_empty() + && self.offer_open_commit_cmd() => + { + self.commit.show(); + NeedsUpdate::COMMANDS + } _ => NeedsUpdate::empty(), }; @@ -295,7 +309,6 @@ impl App { self.index_wd.update(&status.work_dir); self.update_diff(); - self.commit.set_stage_empty(self.index.is_empty()); self.update_commands(); } @@ -413,6 +426,33 @@ impl App { )); } + res.push( + CommandInfo::new( + commands::COMMIT_OPEN, + !self.index.is_empty(), + self.offer_open_commit_cmd(), + ) + .order(-1), + ); + + res.push( + CommandInfo::new( + commands::SELECT_STAGING, + true, + self.focus == Focus::WorkDir, + ) + .order(-2), + ); + + res.push( + CommandInfo::new( + commands::SELECT_UNSTAGED, + true, + self.focus == Focus::Stage, + ) + .order(-2), + ); + res.push( CommandInfo::new( commands::QUIT, @@ -426,6 +466,11 @@ impl App { res } + fn offer_open_commit_cmd(&self) -> bool { + !self.commit.is_visible() + && self.diff_target == DiffTarget::Stage + } + fn components(&self) -> Vec<&dyn Component> { vec![ &self.msg, diff --git a/src/components/commit.rs b/src/components/commit.rs index b16b5222..046dd3b4 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -3,7 +3,6 @@ use super::{ DrawableComponent, }; use crate::{ - keys, queue::{InternalEvent, NeedsUpdate, Queue}, strings, ui, }; @@ -24,7 +23,6 @@ use tui::{ pub struct CommitComponent { msg: String, visible: bool, - stage_empty: bool, queue: Queue, } @@ -62,11 +60,6 @@ impl Component for CommitComponent { out: &mut Vec, _force_all: bool, ) -> CommandBlocking { - out.push(CommandInfo::new( - commands::COMMIT_OPEN, - !self.stage_empty, - !self.visible, - )); out.push(CommandInfo::new( commands::COMMIT_ENTER, self.can_commit(), @@ -100,13 +93,6 @@ impl Component for CommitComponent { }; return true; } - } else if let Event::Key(e) = ev { - if let keys::OPEN_COMMIT = e { - if !self.stage_empty { - self.show(); - return true; - } - } } false } @@ -130,7 +116,6 @@ impl CommitComponent { Self { queue, msg: String::default(), - stage_empty: true, visible: false, } } @@ -171,9 +156,4 @@ impl CommitComponent { fn can_commit(&self) -> bool { !self.msg.is_empty() } - - /// - pub fn set_stage_empty(&mut self, empty: bool) { - self.stage_empty = empty; - } } diff --git a/src/strings.rs b/src/strings.rs index 8d6a9848..a85d98bd 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -67,6 +67,18 @@ pub mod commands { ) .hide_help(); /// + pub static SELECT_STAGING: CommandText = CommandText::new( + "Focus Staging [2]", + "focus/select staging area", + CMD_GROUP_GENERAL, + ); + /// + pub static SELECT_UNSTAGED: CommandText = CommandText::new( + "Focus Unstaged [1]", + "focus/select unstaged area", + CMD_GROUP_GENERAL, + ); + /// pub static COMMIT_OPEN: CommandText = CommandText::new( "Commit [c]", "open commit view (available in non-empty stage)",