fix: diff not correct when switching between same file in stage/unstaged

This commit is contained in:
Stephan Dilly 2020-03-24 20:45:47 +01:00
parent 79284469e3
commit 3d0926d279
3 changed files with 9 additions and 9 deletions

View file

@ -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

View file

@ -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();
}

View file

@ -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;