Skip to content

Commit

Permalink
add ability to search session first, then globally
Browse files Browse the repository at this point in the history
  • Loading branch information
fdncred committed Apr 12, 2024
1 parent a8b9de3 commit fe54004
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,18 +1549,12 @@ impl Reedline {
)
}),
ParseAction::BackwardPrefixSearch => {
self.history
.search(
// TODO: Allow this to work when using history isolation
// Not quite sure how to check that anymore
/*SearchQuery::last_with_prefix_and_cwd(
let history_search_by_session = self
.history
.search(SearchQuery::last_with_prefix_and_cwd(
parsed.prefix.unwrap().to_string(),
self.get_history_session_id(),*/
SearchQuery::last_with_prefix(
parsed_prefix.clone(),
self.get_history_session_id(),
),
)
self.get_history_session_id(),
))
.unwrap_or_else(|_| Vec::new())
.get(index.saturating_sub(1))
.map(|history| {
Expand All @@ -1569,7 +1563,28 @@ impl Reedline {
parsed_prefix.len() + parsed_marker.len(),
history.command_line.clone(),
)
})
});
// If we don't find any history searching by session id, then let's
// search everything, otherwise use the result from the session search
if history_search_by_session.is_none() {
eprintln!("Using global search");
self.history
.search(SearchQuery::last_with_prefix(
parsed_prefix.clone(),
self.get_history_session_id(),
))
.unwrap_or_else(|_| Vec::new())
.get(index.saturating_sub(1))
.map(|history| {
(
parsed.remainder.len(),
parsed_prefix.len() + parsed_marker.len(),
history.command_line.clone(),
)
})
} else {
history_search_by_session
}
}
ParseAction::ForwardSearch => self
.history
Expand Down

0 comments on commit fe54004

Please sign in to comment.