From 8ddb3cdac5829ff532a3c242ed2b060870f9cabd Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 16 May 2021 17:13:43 +0200 Subject: [PATCH] move focus after last file staged --- src/app.rs | 3 +++ src/components/changes.rs | 9 +++++++++ src/queue.rs | 2 ++ src/tabs/status.rs | 7 +++++++ 4 files changed, 21 insertions(+) diff --git a/src/app.rs b/src/app.rs index 9ce52a65..9131b373 100644 --- a/src/app.rs +++ b/src/app.rs @@ -562,6 +562,9 @@ impl App { self.push_tags_popup.push_tags()?; flags.insert(NeedsUpdate::ALL) } + InternalEvent::StatusLastFileMoved => { + self.status_tab.last_file_moved()?; + } }; Ok(flags) diff --git a/src/components/changes.rs b/src/components/changes.rs index 427940e5..6f5cf20b 100644 --- a/src/components/changes.rs +++ b/src/components/changes.rs @@ -87,6 +87,12 @@ impl ChangesComponent { _ => sync::stage_add_file(CWD, path)?, }; + if self.is_empty() { + self.queue.borrow_mut().push_back( + InternalEvent::StatusLastFileMoved, + ); + } + return Ok(true); } @@ -274,6 +280,9 @@ impl Component for ChangesComponent { } else { self.stage_remove_all()?; } + self.queue.borrow_mut().push_back( + InternalEvent::StatusLastFileMoved, + ); Ok(EventState::Consumed) } else if e == self.key_config.status_reset_item && self.is_working_dir diff --git a/src/queue.rs b/src/queue.rs index 6db977b1..423bc1b0 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -48,6 +48,8 @@ pub enum InternalEvent { ShowErrorMsg(String), /// Update(NeedsUpdate), + /// + StatusLastFileMoved, /// open commit msg input OpenCommit, /// diff --git a/src/tabs/status.rs b/src/tabs/status.rs index f265f582..baa31bdf 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -437,6 +437,13 @@ impl Status { } } + pub fn last_file_moved(&mut self) -> Result<()> { + if !self.is_focus_on_diff() && self.is_visible() { + self.switch_focus(self.focus.toggled_focus())?; + } + Ok(()) + } + fn push(&self, force: bool) { if self.can_push() { if let Some(branch) = self.git_branch_name.last() {