diff --git a/CHANGELOG.md b/CHANGELOG.md index bceb31185c..941d323782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * support 'n'/'p' key to move to the next/prev hunk in diff component [[@hamflx](https://github.com/hamflx)] ([#1523](https://github.com/extrawurst/gitui/issues/1523)) * simplify theme overrides [[@cruessler](https://github.com/cruessler)] ([#1367](https://github.com/extrawurst/gitui/issues/1367)) +* fuzzy find commit [[@UUGTech](https://github.com/UUGTech)] ([#1687](https://github.com/extrawurst/gitui/issues/1687)) ### Fixes * fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726)) diff --git a/src/app.rs b/src/app.rs index 1811b508c7..cbee32b264 100644 --- a/src/app.rs +++ b/src/app.rs @@ -926,6 +926,10 @@ impl App { &PathBuf::from(content), ); } + FuzzyFinderTarget::Commits => { + self.revlog.commit_finder_update(idx); + self.stashlist_tab.commit_finder_update(idx); + } } flags diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index ba799eaf71..c58155fa44 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -1,4 +1,7 @@ -use super::utils::logitems::{ItemBatch, LogEntry}; +use super::{ + utils::logitems::{ItemBatch, LogEntry}, + FuzzyFinderTarget, +}; use crate::{ components::{ utils::string_width_align, CommandBlocking, CommandInfo, @@ -636,6 +639,21 @@ impl Component for CommitList { ) { self.checkout(); true + } else if key_match(k, self.key_config.keys.file_find) + { + let mut commits: Vec = Vec::new(); + for e in self.items.iter() { + let hash = e.hash_short.to_string(); + let author = e.author.to_string(); + let msg = e.msg.to_string(); + commits + .push(format!("{hash} {author} {msg}")); + } + self.queue.push(InternalEvent::OpenFuzzyFinder( + commits, + FuzzyFinderTarget::Commits, + )); + false } else { false }; @@ -663,6 +681,11 @@ impl Component for CommitList { true, true, )); + out.push(CommandInfo::new( + strings::commands::find_commit(&self.key_config), + true, + true, + )); CommandBlocking::PassingOn } } diff --git a/src/components/mod.rs b/src/components/mod.rs index 14498adcbb..8646741157 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -238,6 +238,7 @@ pub enum EventState { pub enum FuzzyFinderTarget { Branches, Files, + Commits, } impl EventState { diff --git a/src/keys/key_list.rs b/src/keys/key_list.rs index 134d992d87..d4e6e68ea7 100644 --- a/src/keys/key_list.rs +++ b/src/keys/key_list.rs @@ -104,6 +104,7 @@ pub struct KeysList { pub open_file_tree: GituiKeyEvent, pub file_find: GituiKeyEvent, pub branch_find: GituiKeyEvent, + pub commit_find: GituiKeyEvent, pub force_push: GituiKeyEvent, pub fetch: GituiKeyEvent, pub pull: GituiKeyEvent, @@ -195,6 +196,7 @@ impl Default for KeysList { open_file_tree: GituiKeyEvent::new(KeyCode::Char('F'), KeyModifiers::SHIFT), file_find: GituiKeyEvent::new(KeyCode::Char('f'), KeyModifiers::empty()), branch_find: GituiKeyEvent::new(KeyCode::Char('f'), KeyModifiers::empty()), + commit_find: GituiKeyEvent::new(KeyCode::Char('f'), KeyModifiers::empty()), diff_hunk_next: GituiKeyEvent::new(KeyCode::Char('n'), KeyModifiers::empty()), diff_hunk_prev: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()), stage_unstage_item: GituiKeyEvent::new(KeyCode::Enter, KeyModifiers::empty()), diff --git a/src/strings.rs b/src/strings.rs index 3e1ff80633..7c8f2d7e7f 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -460,6 +460,16 @@ pub mod commands { CMD_GROUP_GENERAL, ) } + pub fn find_commit(key_config: &SharedKeyConfig) -> CommandText { + CommandText::new( + format!( + "Find [{}]", + key_config.get_hint(key_config.keys.commit_find) + ), + "find commit in list", + CMD_GROUP_GENERAL, + ) + } pub fn toggle_tabs_direct( key_config: &SharedKeyConfig, ) -> CommandText { diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index 73ecef0dbb..3d7b32b0b1 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -236,6 +236,10 @@ impl Revlog { )); } } + + pub fn commit_finder_update(&mut self, idx: usize) { + self.list.select_entry(idx); + } } impl DrawableComponent for Revlog { diff --git a/src/tabs/stashlist.rs b/src/tabs/stashlist.rs index 151ec87be1..ef2d4a5c11 100644 --- a/src/tabs/stashlist.rs +++ b/src/tabs/stashlist.rs @@ -145,6 +145,10 @@ impl StashList { Ok(()) } + + pub fn commit_finder_update(&mut self, idx: usize) { + self.list.select_entry(idx); + } } impl DrawableComponent for StashList {