Skip to content

Feat fuzzy find commits #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion src/components/commitlist.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<String> = 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
};
Expand Down Expand Up @@ -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
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub enum EventState {
pub enum FuzzyFinderTarget {
Branches,
Files,
Commits,
}

impl EventState {
Expand Down
2 changes: 2 additions & 0 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
Expand Down
10 changes: 10 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ impl Revlog {
));
}
}

pub fn commit_finder_update(&mut self, idx: usize) {
self.list.select_entry(idx);
}
}

impl DrawableComponent for Revlog {
Expand Down
4 changes: 4 additions & 0 deletions src/tabs/stashlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down