Skip to content

Commit 34deaa8

Browse files
committed
hook up new search popup
1 parent b5bbf98 commit 34deaa8

File tree

6 files changed

+85
-42
lines changed

6 files changed

+85
-42
lines changed

asyncgit/src/sync/logwalker.rs

+29-23
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,33 @@ bitflags! {
7676

7777
impl Default for FilterSearchOptions {
7878
fn default() -> Self {
79-
Self::all()
79+
Self::MESSAGE
8080
}
8181
}
8282

83+
///
84+
#[derive(Default, Debug)]
85+
pub struct LogFilterSearchOptions {
86+
///
87+
pub search_pattern: String,
88+
///
89+
pub filters: FilterSearchOptions,
90+
}
91+
8392
///
8493
#[derive(Default)]
8594
pub struct LogFilterSearch {
8695
///
8796
pub matcher: fuzzy_matcher::skim::SkimMatcherV2,
8897
///
89-
pub search_pattern: String,
90-
///
91-
pub options: FilterSearchOptions,
98+
pub options: LogFilterSearchOptions,
9299
}
93100

94101
impl LogFilterSearch {
95102
///
96-
pub fn new(
97-
search_pattern: String,
98-
options: FilterSearchOptions,
99-
) -> Self {
103+
pub fn new(options: LogFilterSearchOptions) -> Self {
100104
Self {
101105
matcher: fuzzy_matcher::skim::SkimMatcherV2::default(),
102-
search_pattern,
103106
options,
104107
}
105108
}
@@ -114,7 +117,7 @@ impl LogFilterSearch {
114117
self.matcher
115118
.fuzzy_match(
116119
file,
117-
self.search_pattern.as_str(),
120+
self.options.search_pattern.as_str(),
118121
)
119122
.is_some()
120123
})
@@ -131,7 +134,7 @@ impl LogFilterSearch {
131134
self.matcher
132135
.fuzzy_match(
133136
file,
134-
self.search_pattern.as_str(),
137+
self.options.search_pattern.as_str(),
135138
)
136139
.is_some()
137140
})
@@ -152,12 +155,13 @@ pub fn filter_commit_by_search(
152155

153156
let msg_match = filter
154157
.options
158+
.filters
155159
.contains(FilterSearchOptions::MESSAGE)
156160
.then(|| {
157161
commit.message().and_then(|msg| {
158162
filter.matcher.fuzzy_match(
159163
msg,
160-
filter.search_pattern.as_str(),
164+
filter.options.search_pattern.as_str(),
161165
)
162166
})
163167
})
@@ -166,6 +170,7 @@ pub fn filter_commit_by_search(
166170

167171
let file_match = filter
168172
.options
173+
.filters
169174
.contains(FilterSearchOptions::FILENAMES)
170175
.then(|| {
171176
get_commit_diff(
@@ -263,7 +268,6 @@ mod tests {
263268
commit, get_commits_info, stage_add_file,
264269
tests::repo_init_empty,
265270
};
266-
use fuzzy_matcher::skim::SkimMatcherV2;
267271
use pretty_assertions::assert_eq;
268272
use std::{fs::File, io::Write, path::Path};
269273

@@ -389,11 +393,12 @@ mod tests {
389393
);
390394
write_commit_file(&repo, "foo", "b", "commit3");
391395

392-
let log_filter = filter_commit_by_search(LogFilterSearch {
393-
options: FilterSearchOptions::MESSAGE,
394-
matcher: SkimMatcherV2::default(),
395-
search_pattern: String::from("my msg"),
396-
});
396+
let log_filter = filter_commit_by_search(
397+
LogFilterSearch::new(LogFilterSearchOptions {
398+
filters: FilterSearchOptions::MESSAGE,
399+
search_pattern: String::from("my msg"),
400+
}),
401+
);
397402

398403
let mut items = Vec::new();
399404
let mut walker = LogWalker::new(&repo, 100)
@@ -404,11 +409,12 @@ mod tests {
404409
assert_eq!(items.len(), 1);
405410
assert_eq!(items[0], second_commit_id);
406411

407-
let log_filter = filter_commit_by_search(LogFilterSearch {
408-
options: FilterSearchOptions::FILENAMES,
409-
matcher: SkimMatcherV2::default(),
410-
search_pattern: String::from("fo"),
411-
});
412+
let log_filter = filter_commit_by_search(
413+
LogFilterSearch::new(LogFilterSearchOptions {
414+
filters: FilterSearchOptions::FILENAMES,
415+
search_pattern: String::from("fo"),
416+
}),
417+
);
412418

413419
let mut items = Vec::new();
414420
let mut walker = LogWalker::new(&repo, 100)

asyncgit/src/sync/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ pub use hunks::{reset_hunk, stage_hunk, unstage_hunk};
6565
pub use ignore::add_to_ignore;
6666
pub use logwalker::{
6767
diff_contains_file, filter_commit_by_search, FilterSearchOptions,
68-
LogFilterSearch, LogWalker, LogWalkerFilter,
68+
LogFilterSearch, LogFilterSearchOptions, LogWalker,
69+
LogWalkerFilter,
6970
};
7071
pub use merge::{
7172
abort_pending_rebase, abort_pending_state,

src/app.rs

+3
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,9 @@ impl App {
974974
InternalEvent::OpenResetPopup(id) => {
975975
self.reset_popup.open(id)?;
976976
}
977+
InternalEvent::CommitSearch(options) => {
978+
self.revlog.search(options);
979+
}
977980
};
978981

979982
Ok(flags)

src/components/log_search_popup.rs

+39-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
#![allow(dead_code)]
2-
31
use super::{
42
visibility_blocking, CommandBlocking, CommandInfo, Component,
53
DrawableComponent, EventState, TextInputComponent,
64
};
75
use crate::{
86
keys::{key_match, SharedKeyConfig},
9-
queue::Queue,
7+
queue::{InternalEvent, Queue},
108
strings::{self},
119
ui::{self, style::SharedTheme},
1210
};
1311
use anyhow::Result;
14-
use asyncgit::sync::FilterSearchOptions;
12+
use asyncgit::sync::{FilterSearchOptions, LogFilterSearchOptions};
1513
use crossterm::event::Event;
1614
use ratatui::{
1715
backend::Backend,
1816
layout::{
1917
Alignment, Constraint, Direction, Layout, Margin, Rect,
2018
},
21-
style::Style,
2219
text::{Line, Span},
2320
widgets::{Block, Borders, Clear, Paragraph},
2421
Frame,
@@ -69,6 +66,13 @@ impl LogSearchPopupComponent {
6966

7067
fn execute_search(&mut self) {
7168
self.hide();
69+
70+
self.queue.push(InternalEvent::CommitSearch(
71+
LogFilterSearchOptions {
72+
filters: self.options,
73+
search_pattern: self.find_text.get_text().to_string(),
74+
},
75+
));
7276
}
7377

7478
fn get_text(&self) -> Vec<Line> {
@@ -81,10 +85,37 @@ impl LogSearchPopupComponent {
8185
" "
8286
};
8387

88+
let x_files = if self
89+
.options
90+
.contains(FilterSearchOptions::FILENAMES)
91+
{
92+
"X"
93+
} else {
94+
" "
95+
};
96+
97+
let theme = self.theme.text(false, false);
98+
txt.push(Line::from(vec![Span::styled(
99+
"[X] fuzzy search",
100+
theme,
101+
)]));
102+
txt.push(Line::from(vec![Span::styled(
103+
format!("[{x_message}] messages",),
104+
theme,
105+
)]));
106+
txt.push(Line::from(vec![Span::styled(
107+
format!("[{x_files}] commited files",),
108+
theme,
109+
)]));
84110
txt.push(Line::from(vec![Span::styled(
85-
format!("[{x_message}] message",),
86-
Style::default(),
111+
"[ ] changes",
112+
theme,
113+
)]));
114+
txt.push(Line::from(vec![Span::styled(
115+
"[ ] authors",
116+
theme,
87117
)]));
118+
txt.push(Line::from(vec![Span::styled("[ ] hashes", theme)]));
88119

89120
txt
90121
}
@@ -97,7 +128,7 @@ impl DrawableComponent for LogSearchPopupComponent {
97128
area: Rect,
98129
) -> Result<()> {
99130
if self.is_visible() {
100-
const SIZE: (u16, u16) = (60, 8);
131+
const SIZE: (u16, u16) = (60, 10);
101132
let area =
102133
ui::centered_rect_absolute(SIZE.0, SIZE.1, area);
103134

src/queue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use crate::{
66
tabs::StashingOptions,
77
};
88
use asyncgit::{
9-
sync::{diff::DiffLinePosition, CommitId},
9+
sync::{
10+
diff::DiffLinePosition, CommitId, LogFilterSearchOptions,
11+
},
1012
PushType,
1113
};
1214
use bitflags::bitflags;
@@ -132,6 +134,8 @@ pub enum InternalEvent {
132134
OpenResetPopup(CommitId),
133135
///
134136
RewordCommit(CommitId),
137+
///
138+
CommitSearch(LogFilterSearchOptions),
135139
}
136140

137141
/// single threaded simple queue for components to communicate with each other

src/tabs/revlog.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use anyhow::Result;
1616
use asyncgit::{
1717
asyncjob::AsyncSingleJob,
1818
sync::{
19-
self, filter_commit_by_search, CommitId, FilterSearchOptions,
20-
LogFilterSearch, RepoPathRef,
19+
self, filter_commit_by_search, CommitId, LogFilterSearch,
20+
LogFilterSearchOptions, RepoPathRef,
2121
},
2222
AsyncBranchesJob, AsyncGitNotification, AsyncLog, AsyncTags,
2323
CommitFilesParams, FetchStatus,
@@ -273,15 +273,13 @@ impl Revlog {
273273
}
274274
}
275275

276-
fn find(&mut self) {
276+
pub fn search(&mut self, options: LogFilterSearchOptions) {
277277
if self.git_log_find.is_none() {
278-
log::info!("start search");
278+
log::info!("start search: {:?}", options);
279279

280-
let filter =
281-
filter_commit_by_search(LogFilterSearch::new(
282-
String::from("README.md"),
283-
FilterSearchOptions::all(),
284-
));
280+
let filter = filter_commit_by_search(
281+
LogFilterSearch::new(options),
282+
);
285283

286284
let async_find = AsyncLog::new(
287285
self.repo.borrow().clone(),

0 commit comments

Comments
 (0)