From 87254045c32a0a699b21993e5cbe8c411e5ca6fe Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 22 Mar 2020 02:26:32 +0100 Subject: [PATCH] trigger update only after sending commit --- src/app.rs | 9 ++++++-- src/components/commit.rs | 47 ++++++++++++++++------------------------ src/git_utils.rs | 18 +-------------- src/keys.rs | 1 + 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/app.rs b/src/app.rs index eadd9e46..ed7c4c82 100644 --- a/src/app.rs +++ b/src/app.rs @@ -137,8 +137,10 @@ impl App { /// pub fn event(&mut self, ev: Event) { trace!("event: {:?}", ev); - if self.commit.event(ev) { - self.update_diff(); + if self.commit.is_visible() && self.commit.event(ev) { + if !self.commit.is_visible() { + self.update(); + } return; } @@ -183,6 +185,9 @@ impl App { self.index_reset(); self.update(); } + keys::OPEN_COMMIT if !self.index.is_empty() => { + self.commit.show(); + } _ => (), }; } diff --git a/src/components/commit.rs b/src/components/commit.rs index 39fc835b..487a85ce 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -60,35 +60,26 @@ impl Component for CommitComponent { } fn event(&mut self, ev: Event) -> bool { - if self.visible { - if let Event::Key(e) = ev { - return match e.code { - KeyCode::Esc => { - self.hide(); - true - } - KeyCode::Char(c) => { - self.msg.push(c); - true - } - KeyCode::Enter if self.can_commit() => { - self.commit(); - true - } - KeyCode::Backspace if self.msg.len() > 0 => { - self.msg.pop().unwrap(); - true - } - _ => false, - }; - } - } else { - if ev == Event::Key(KeyCode::Char('c').into()) { - if !git_utils::index_empty() { - self.show(); - return true; + if let Event::Key(e) = ev { + return match e.code { + KeyCode::Esc => { + self.hide(); + true } - } + KeyCode::Char(c) => { + self.msg.push(c); + true + } + KeyCode::Enter if self.can_commit() => { + self.commit(); + true + } + KeyCode::Backspace if self.msg.len() > 0 => { + self.msg.pop().unwrap(); + true + } + _ => false, + }; } false diff --git a/src/git_utils.rs b/src/git_utils.rs index 34036a87..b99de9ae 100644 --- a/src/git_utils.rs +++ b/src/git_utils.rs @@ -1,7 +1,6 @@ use git2::{ build::CheckoutBuilder, DiffFormat, DiffOptions, IndexAddOption, - ObjectType, Repository, RepositoryOpenFlags, StatusOptions, - StatusShow, + ObjectType, Repository, RepositoryOpenFlags, }; use scopetime::scope_time; use std::path::Path; @@ -134,21 +133,6 @@ pub fn commit(msg: &String) { .unwrap(); } -/// -pub fn index_empty() -> bool { - scope_time!("index_empty"); - - let repo = repo(); - - let statuses = repo - .statuses(Some( - StatusOptions::default().show(StatusShow::Index), - )) - .unwrap(); - - statuses.is_empty() -} - pub fn stage_add(path: &Path) -> bool { scope_time!("stage_add"); diff --git a/src/keys.rs b/src/keys.rs index b2b17603..94f828f3 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -15,3 +15,4 @@ pub const STATUS_RESET_FILE: KeyEvent = no_mod(KeyCode::Char('D')); pub const STATUS_STAGE_FILE: KeyEvent = no_mod(KeyCode::Enter); pub const EXIT_1: KeyEvent = no_mod(KeyCode::Esc); pub const EXIT_2: KeyEvent = no_mod(KeyCode::Char('q')); +pub const OPEN_COMMIT: KeyEvent = no_mod(KeyCode::Char('c'));