Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* use [tombi](https://github.com/tombi-toml/tombi) for all toml file formatting
* open the external editor from the status diff view [[@WaterWhisperer](https://github.com/WaterWhisperer)] ([#2805](https://github.com/gitui-org/gitui/issues/2805))
* auto return to the tree view after staging the last hunk from the status diff view [[@WaterWhisperer](https://github.com/WaterWhisperer)] ([#2748](https://github.com/gitui-org/gitui/issues/2748))

### Fixes
* crash when opening submodule ([#2895](https://github.com/gitui-org/gitui/issues/2895))
Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/statustree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl StatusTree {
self.update_visibility(None, 0, true);
self.available_selections = self.setup_available_selections();

//NOTE: now that visibility is set we can make sure selection is visible
// NOTE: now that visibility is set we can make sure selection is visible
if let Some(idx) = self.selection {
self.selection = Some(self.find_visible_idx(idx));
}
Expand Down
28 changes: 27 additions & 1 deletion src/tabs/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,27 @@ impl Status {
}

fn update_status(&mut self) -> Result<()> {
let diff_before_update = self.diff.current();

let stage_status = self.git_status_stage.last()?;
self.index.set_items(&stage_status.items)?;

let workdir_status = self.git_status_workdir.last()?;
self.index_wd.set_items(&workdir_status.items)?;

self.update_diff()?;
if Self::should_exit_diff_focus_after_status_update(
self.git_action_executed,
self.is_focus_on_diff(),
&diff_before_update,
self.selected_path().as_ref(),
) {
self.switch_focus(match self.diff_target {
DiffTarget::Stage => Focus::Stage,
DiffTarget::WorkingDir => Focus::WorkDir,
})?;
} else {
self.update_diff()?;
}

if self.git_action_executed {
self.git_action_executed = false;
Expand All @@ -482,6 +496,18 @@ impl Status {
Ok(())
}

fn should_exit_diff_focus_after_status_update(
git_action_executed: bool,
is_focus_on_diff: bool,
diff_before_update: &(String, bool),
selected_path_after_update: Option<&(String, bool)>,
) -> bool {
git_action_executed
&& is_focus_on_diff
&& !diff_before_update.0.is_empty()
&& selected_path_after_update != Some(diff_before_update)
}

///
pub fn update_diff(&mut self) -> Result<()> {
if let Some((path, is_stage)) = self.selected_path() {
Expand Down
Loading