diff options
author | extrawurst <776816+extrawurst@users.noreply.github.com> | 2023-08-31 10:41:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 10:41:52 +0200 |
commit | 5be397b335b33787d6b5710567028b61f5cf1b28 (patch) | |
tree | d5a249bdb371c7e4614ea8303d6bbf8149882384 /src | |
parent | 16c97edb4d2190cab6f92a057aefb4d9a4f66703 (diff) |
stash list does not update after pop/drop (#1865)
* move to stashlist after stashing
* move to status after stash popping
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 28 | ||||
-rw-r--r-- | src/components/commitlist.rs | 28 | ||||
-rw-r--r-- | src/components/stashmsg.rs | 10 | ||||
-rw-r--r-- | src/queue.rs | 10 | ||||
-rw-r--r-- | src/tabs/stashlist.rs | 2 |
5 files changed, 62 insertions, 16 deletions
@@ -20,7 +20,8 @@ use crate::{ options::{Options, SharedOptions}, popup_stack::PopupStack, queue::{ - Action, InternalEvent, NeedsUpdate, Queue, StackablePopupOpen, + Action, AppTabs, InternalEvent, NeedsUpdate, Queue, + StackablePopupOpen, }, setup_popups, strings::{self, ellipsis_trim_start, order}, @@ -697,15 +698,15 @@ impl App { fn switch_tab(&mut self, k: &KeyEvent) -> Result<()> { if key_match(k, self.key_config.keys.tab_status) { - self.set_tab(0)?; + self.switch_to_tab(&AppTabs::Status)?; } else if key_match(k, self.key_config.keys.tab_log) { - self.set_tab(1)?; + self.switch_to_tab(&AppTabs::Log)?; } else if key_match(k, self.key_config.keys.tab_files) { - self.set_tab(2)?; + self.switch_to_tab(&AppTabs::Files)?; } else if key_match(k, self.key_config.keys.tab_stashing) { - self.set_tab(3)?; + self.switch_to_tab(&AppTabs::Stashing)?; } else if key_match(k, self.key_config.keys.tab_stashes) { - self.set_tab(4)?; + self.switch_to_tab(&AppTabs::Stashlist)?; } Ok(()) @@ -727,6 +728,17 @@ impl App { Ok(()) } + fn switch_to_tab(&mut self, tab: &AppTabs) -> Result<()> { + match tab { + AppTabs::Status => self.set_tab(0)?, + AppTabs::Log => self.set_tab(1)?, + AppTabs::Files => self.set_tab(2)?, + AppTabs::Stashing => self.set_tab(3)?, + AppTabs::Stashlist => self.set_tab(4)?, + } + Ok(()) + } + fn update_commands(&mut self) { if self.help.is_visible() { self.help.set_cmds(self.commands(true)); @@ -855,6 +867,10 @@ impl App { self.tags_popup.open()?; } InternalEvent::TabSwitchStatus => self.set_tab(0)?, + InternalEvent::TabSwitch(tab) => { + self.switch_to_tab(&tab)?; + flags.insert(NeedsUpdate::ALL); + } InternalEvent::SelectCommitInRevlog(id) => { if let Err(error) = self.revlog.select_commit(id) { self.queue.push(InternalEvent::ShowErrorMsg( diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 2e8b80c3..9d8114b7 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -225,8 +225,11 @@ impl CommitList { /// pub fn set_commits(&mut self, commits: Vec<CommitId>) { - self.commits = commits; - self.fetch_commits(false); + if commits != self.commits { + self.items.clear(); + self.commits = commits; + self.fetch_commits(false); + } } /// @@ -724,6 +727,19 @@ impl CommitList { self.items.needs_data(idx, idx_max) } + // checks if first entry in items is the same commit as we expect + fn is_list_in_sync(&self) -> bool { + self.items + .index_offset_raw() + .and_then(|index| { + self.items + .iter() + .next() + .map(|item| item.id == self.commits[index]) + }) + .unwrap_or_default() + } + fn fetch_commits(&mut self, force: bool) { let want_min = self.selection().saturating_sub(SLICE_SIZE / 2); @@ -731,13 +747,13 @@ impl CommitList { let want_min = want_min.min(commits); - if !self + let index_in_sync = self .items .index_offset_raw() .map(|index| want_min == index) - .unwrap_or_default() - || force - { + .unwrap_or_default(); + + if !index_in_sync || !self.is_list_in_sync() || force { let slice_end = want_min.saturating_add(SLICE_SIZE).min(commits); diff --git a/src/components/stashmsg.rs b/src/components/stashmsg.rs index bd739311..d30f68fc 100644 --- a/src/components/stashmsg.rs +++ b/src/components/stashmsg.rs @@ -5,7 +5,7 @@ use super::{ }; use crate::{ keys::{key_match, SharedKeyConfig}, - queue::{InternalEvent, NeedsUpdate, Queue}, + queue::{AppTabs, InternalEvent, Queue}, strings, tabs::StashingOptions, ui::style::SharedTheme, @@ -79,9 +79,11 @@ impl Component for StashMsgComponent { self.input.clear(); self.hide(); - self.queue.push(InternalEvent::Update( - NeedsUpdate::ALL, - )); + self.queue.push( + InternalEvent::TabSwitch( + AppTabs::Stashlist, + ), + ); } Err(e) => { self.hide(); diff --git a/src/queue.rs b/src/queue.rs index 3de68318..68531985 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -70,6 +70,14 @@ pub enum StackablePopupOpen { CompareCommits(InspectCommitOpen), } +pub enum AppTabs { + Status, + Log, + Files, + Stashing, + Stashlist, +} + /// pub enum InternalEvent { /// @@ -91,6 +99,8 @@ pub enum InternalEvent { /// TabSwitchStatus, /// + TabSwitch(AppTabs), + /// SelectCommitInRevlog(CommitId), /// TagCommit(CommitId), diff --git a/src/tabs/stashlist.rs b/src/tabs/stashlist.rs index 67e40087..f12822e4 100644 --- a/src/tabs/stashlist.rs +++ b/src/tabs/stashlist.rs @@ -136,6 +136,8 @@ impl StashList { self.list.clear_marked(); self.update()?; + self.queue.push(InternalEvent::TabSwitchStatus); + Ok(()) } } |