From 8b37a22e4dee6ed1220319a8ebd710e7917de999 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Thu, 19 Mar 2020 21:58:28 +0100 Subject: [PATCH] keep highlighting current diff file --- README.md | 1 - src/app.rs | 18 ++++++++++++------ src/components/index.rs | 13 ++++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cbe719e8..455ba6aa 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ Over the last 2 years my go-to GUI tool for this was [fork](https://git-fork.com * [x] inspect diffs * [x] commit * [x] [input polling in thread](assets/perf_compare.jpg) -* [ ] highlight current file being diffed * [ ] support non-root git folder wd * [ ] show content of new files * [ ] indicate file status (modified,added,removed) diff --git a/src/app.rs b/src/app.rs index 3e8098c7..e2271091 100644 --- a/src/app.rs +++ b/src/app.rs @@ -19,6 +19,7 @@ use tui::{ }; /// +#[derive(PartialEq)] enum DiffTarget { Stage, WorkingDir, @@ -271,26 +272,31 @@ impl App { match self.focus { Focus::Status => { - self.diff_target = DiffTarget::WorkingDir; - self.index_wd.focus(true); - self.index.focus(false); + self.set_diff_target(DiffTarget::WorkingDir); self.diff.focus(false); } Focus::Stage => { - self.diff_target = DiffTarget::Stage; - self.index.focus(true); - self.index_wd.focus(false); + self.set_diff_target(DiffTarget::Stage); self.diff.focus(false); } Focus::Diff => { self.index.focus(false); self.index_wd.focus(false); + self.diff.focus(true); } }; } } + fn set_diff_target(&mut self, target: DiffTarget) { + self.diff_target = target; + let is_stage = self.diff_target == DiffTarget::Stage; + + self.index_wd.focus_select(!is_stage); + self.index.focus_select(is_stage); + } + fn index_add_remove(&mut self) { if self.index_wd.focused() { if let Some(i) = self.index_wd.selection() { diff --git a/src/components/index.rs b/src/components/index.rs index aa3702a3..c3d4513b 100644 --- a/src/components/index.rs +++ b/src/components/index.rs @@ -16,6 +16,7 @@ pub struct IndexComponent { index_type: StatusShow, selection: Option, focused: bool, + show_selection: bool, } impl IndexComponent { @@ -31,6 +32,7 @@ impl IndexComponent { index_type, selection: None, focused: focus, + show_selection: focus, } } /// @@ -53,6 +55,11 @@ impl IndexComponent { } } + pub fn focus_select(&mut self, focus: bool) { + self.focus(focus); + self.show_selection = focus; + } + fn move_selection(&mut self, delta: i32) { let items_len = self.items.len(); if items_len > 0 { @@ -79,7 +86,11 @@ impl Component for IndexComponent { .map(|e| e.path.clone()) .collect::>() .as_slice(), - if self.focused { self.selection } else { None }, + if self.show_selection { + self.selection + } else { + None + }, self.focused, ); }