From 8f6a7bd330d2409f25e13d8581006642b093d798 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Fri, 1 May 2020 22:20:30 +0200 Subject: [PATCH] fix rare showing of wrong diff --- asyncgit/src/diff.rs | 6 +++--- src/app.rs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/asyncgit/src/diff.rs b/asyncgit/src/diff.rs index a375b743..aad272b8 100644 --- a/asyncgit/src/diff.rs +++ b/asyncgit/src/diff.rs @@ -10,7 +10,7 @@ use std::{ }; /// -#[derive(Default, Hash, Clone)] +#[derive(Default, Hash, Clone, PartialEq)] pub struct DiffParams(pub String, pub bool); struct Request(R, Option); @@ -42,10 +42,10 @@ impl AsyncDiff { } /// - pub fn last(&mut self) -> Option { + pub fn last(&mut self) -> Option<(DiffParams, FileDiff)> { let last = self.last.lock().unwrap(); if let Some(res) = last.clone() { - Some(res.result) + Some((res.params, res.result)) } else { None } diff --git a/src/app.rs b/src/app.rs index 134fe815..c60bd5eb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -281,8 +281,10 @@ impl App { if self.diff.current() == (path.clone(), is_stage) { // we are already showing a diff of the right file // maybe the diff changed (outside file change) - if let Some(last) = self.git_diff.last() { - self.diff.update(path, is_stage, last); + if let Some((params, last)) = self.git_diff.last() { + if params == diff_params { + self.diff.update(path, is_stage, last); + } } } else { // we dont show the right diff right now, so we need to request