Skip to content

Commit b294a65

Browse files
committed
Switch focus when working directory or stage becomes empty
If the focus is on the working directory and it becomes empty (no files are listed) by either staging the last file or using the _Stage all_ command, the focus will be moved to the stage automatically. It works the same for when the stage becomes empty, by moving the focus to the working directory. If the focus is on the diff area, the focus will not be moved when either the working directory or the stage becomes empty. Fixes #215
1 parent 079f045 commit b294a65

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Diff for: src/tabs/status.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub struct Status {
4646
git_status_workdir: AsyncStatus,
4747
git_status_stage: AsyncStatus,
4848
queue: Queue,
49+
git_action_executed: bool,
4950
}
5051

5152
impl DrawableComponent for Status {
@@ -130,6 +131,7 @@ impl Status {
130131
git_diff: AsyncDiff::new(sender.clone()),
131132
git_status_workdir: AsyncStatus::new(sender.clone()),
132133
git_status_stage: AsyncStatus::new(sender.clone()),
134+
git_action_executed: false,
133135
}
134136
}
135137

@@ -231,14 +233,29 @@ impl Status {
231233
}
232234

233235
fn update_status(&mut self) -> Result<()> {
234-
let status = self.git_status_stage.last()?;
235-
self.index.set_items(&status.items)?;
236+
let stage_status = self.git_status_stage.last()?;
237+
self.index.set_items(&stage_status.items)?;
236238

237-
let status = self.git_status_workdir.last()?;
238-
self.index_wd.set_items(&status.items)?;
239+
let workdir_status = self.git_status_workdir.last()?;
240+
self.index_wd.set_items(&workdir_status.items)?;
239241

240242
self.update_diff()?;
241243

244+
if self.git_action_executed {
245+
self.git_action_executed = false;
246+
247+
if self.focus == Focus::WorkDir
248+
&& workdir_status.items.is_empty()
249+
&& !stage_status.items.is_empty()
250+
{
251+
self.switch_focus(Focus::Stage)?;
252+
} else if self.focus == Focus::Stage
253+
&& stage_status.items.is_empty()
254+
{
255+
self.switch_focus(Focus::WorkDir)?;
256+
}
257+
}
258+
242259
Ok(())
243260
}
244261

@@ -371,6 +388,7 @@ impl Component for Status {
371388
fn event(&mut self, ev: crossterm::event::Event) -> Result<bool> {
372389
if self.visible {
373390
if event_pump(ev, self.components_mut().as_mut_slice())? {
391+
self.git_action_executed = true;
374392
return Ok(true);
375393
}
376394

0 commit comments

Comments
 (0)