summaryrefslogtreecommitdiffstats
path: root/src/tabs
diff options
context:
space:
mode:
authorextrawurst <776816+extrawurst@users.noreply.github.com>2023-08-27 11:25:16 +0200
committerGitHub <noreply@github.com>2023-08-27 11:25:16 +0200
commit2675934027e83f6b7119dec45055d34ee1f7b20f (patch)
treea958f239c4c766360c8f906a650022104649f98f /src/tabs
parentc68fa3e87b75d2a2b566faffbfcca77de28240be (diff)
Index of search result (#1840)
Diffstat (limited to 'src/tabs')
-rw-r--r--src/tabs/revlog.rs50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs
index 0bdb87f5..7c38c850 100644
--- a/src/tabs/revlog.rs
+++ b/src/tabs/revlog.rs
@@ -23,6 +23,7 @@ use asyncgit::{
};
use crossbeam_channel::Sender;
use crossterm::event::Event;
+use indexmap::IndexSet;
use ratatui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
@@ -30,11 +31,10 @@ use ratatui::{
widgets::{Block, Borders, Paragraph},
Frame,
};
-use std::{collections::HashSet, rc::Rc, time::Duration};
+use std::{rc::Rc, time::Duration};
use sync::CommitTags;
struct LogSearchResult {
- commits: usize,
options: LogFilterSearchOptions,
duration: Duration,
}
@@ -280,16 +280,14 @@ impl Revlog {
false
} else {
let results = search.extract_items()?;
- let commits = results.len();
let duration = search.get_last_duration()?;
- self.list.set_highlighting(Some(
- results.into_iter().collect::<HashSet<_>>(),
- ));
+ self.list.set_highlighting(Some(Rc::new(
+ results.into_iter().collect::<IndexSet<_>>(),
+ )));
self.search =
LogSearch::Results(LogSearchResult {
- commits,
options: options.clone(),
duration,
});
@@ -306,22 +304,28 @@ impl Revlog {
}
fn draw_search<B: Backend>(&self, f: &mut Frame<B>, area: Rect) {
- let text = match &self.search {
- LogSearch::Searching(_, options) => {
- format!(
- "'{}' (pending results...)",
- options.search_pattern.clone()
- )
- }
+ let (text, title) = match &self.search {
+ LogSearch::Searching(_, options) => (
+ format!("'{}'", options.search_pattern.clone()),
+ String::from("(pending results...)"),
+ ),
LogSearch::Results(results) => {
- format!(
- "'{}' (hits: {}) (duration: {:?})",
- results.options.search_pattern.clone(),
- results.commits,
- results.duration,
+ let info = self.list.highlighted_selection_info();
+
+ (
+ format!(
+ "'{}' (duration: {:?})",
+ results.options.search_pattern.clone(),
+ results.duration,
+ ),
+ format!(
+ "({}/{})",
+ (info.0 + 1).min(info.1),
+ info.1
+ ),
)
}
- LogSearch::Off => String::new(),
+ LogSearch::Off => (String::new(), String::new()),
};
f.render_widget(
@@ -329,7 +333,11 @@ impl Revlog {
.block(
Block::default()
.title(Span::styled(
- strings::POPUP_TITLE_LOG_SEARCH,
+ format!(
+ "{} {}",
+ strings::POPUP_TITLE_LOG_SEARCH,
+ title
+ ),
self.theme.title(true),
))
.borders(Borders::ALL)