From 3d0926d2797955f704e42cf820cb7af40269bc0c Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Tue, 24 Mar 2020 20:45:47 +0100 Subject: [PATCH] fix: diff not correct when switching between same file in stage/unstaged --- README.md | 1 - src/app.rs | 4 ++-- src/components/diff.rs | 13 +++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 16d0c332..73b5b4b3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,6 @@ gitui * [ ] fix: dont show scroll option when any popup open * [ ] fix: diff is not updated when changed -* [ ] fix: diff is updated when some hunks of the same file where diffed in unstaged before * [ ] better help command * [ ] confirm destructive commands (revert/reset) * [ ] (un)staging selected hunks diff --git a/src/app.rs b/src/app.rs index b4cc9fe6..356da077 100644 --- a/src/app.rs +++ b/src/app.rs @@ -241,11 +241,11 @@ impl App { if let Some(i) = idx.selection() { let path = i.path; - if self.diff.path() != path { + if self.diff.current() != (path.clone(), is_stage) { if let Some(diff) = self.git_diff.request(path.clone(), is_stage) { - self.diff.update(path.clone(), diff); + self.diff.update(path.clone(), is_stage, diff); } else { self.diff.clear(); } diff --git a/src/components/diff.rs b/src/components/diff.rs index a7b5dc2e..6a2b901b 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -18,7 +18,7 @@ pub struct DiffComponent { diff: Diff, scroll: u16, focused: bool, - current_path: String, + current: (String, bool), } impl DiffComponent { @@ -27,17 +27,18 @@ impl DiffComponent { self.diff.0.len() > 1 } /// - pub fn path(&self) -> String { - self.current_path.clone() + pub fn current(&self) -> (String, bool) { + self.current.clone() } /// pub fn clear(&mut self) { - self.current_path.clear(); + self.current.0.clear(); self.diff = Diff::default(); } /// - pub fn update(&mut self, path: String, diff: Diff) { - self.current_path = path; + pub fn update(&mut self, path: String, stage: bool, diff: Diff) { + self.current = (path, stage); + if diff != self.diff { self.diff = diff; self.scroll = 0;