mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 14:22:37 +03:00
wezterm: add case insensitive search option
This commit is contained in:
parent
6b939c9048
commit
7f83d2172c
@ -190,7 +190,7 @@ impl Tab for SearchOverlay {
|
|||||||
self.delegate.erase_scrollback()
|
self.delegate.erase_scrollback()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search(&self, _pattern: &Pattern) -> Vec<SearchResult> {
|
fn search(&self, _pattern: Pattern) -> Vec<SearchResult> {
|
||||||
// You can't search the search bar
|
// You can't search the search bar
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ impl SearchRenderable {
|
|||||||
self.dirty_results.add(bar_pos);
|
self.dirty_results.add(bar_pos);
|
||||||
|
|
||||||
if !self.pattern.is_empty() {
|
if !self.pattern.is_empty() {
|
||||||
self.results = self.delegate.search(&self.pattern);
|
self.results = self.delegate.search(self.pattern.clone());
|
||||||
self.results.sort();
|
self.results.sort();
|
||||||
|
|
||||||
self.recompute_results();
|
self.recompute_results();
|
||||||
|
@ -104,10 +104,15 @@ impl Tab for LocalTab {
|
|||||||
self.terminal.borrow().get_current_dir().cloned()
|
self.terminal.borrow().get_current_dir().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search(&self, pattern: &Pattern) -> Vec<SearchResult> {
|
fn search(&self, mut pattern: Pattern) -> Vec<SearchResult> {
|
||||||
let term = self.terminal.borrow();
|
let term = self.terminal.borrow();
|
||||||
let screen = term.screen();
|
let screen = term.screen();
|
||||||
|
|
||||||
|
if let Pattern::CaseInSensitiveString(s) = &mut pattern {
|
||||||
|
// normalize the case so we match everything lowercase
|
||||||
|
*s = s.to_lowercase()
|
||||||
|
}
|
||||||
|
|
||||||
let mut results = vec![];
|
let mut results = vec![];
|
||||||
let mut haystack = String::new();
|
let mut haystack = String::new();
|
||||||
let mut coords = vec![];
|
let mut coords = vec![];
|
||||||
@ -137,7 +142,10 @@ impl Tab for LocalTab {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match pattern {
|
match pattern {
|
||||||
Pattern::CaseSensitiveString(s) => {
|
// Rust only provides a case sensitive match_indices function, so
|
||||||
|
// we have to pre-arrange to lowercase both the pattern and the
|
||||||
|
// haystack strings
|
||||||
|
Pattern::CaseInSensitiveString(s) | Pattern::CaseSensitiveString(s) => {
|
||||||
for (idx, s) in haystack.match_indices(s) {
|
for (idx, s) in haystack.match_indices(s) {
|
||||||
let (start_x, start_y) = haystack_idx_to_coord(idx, coords);
|
let (start_x, start_y) = haystack_idx_to_coord(idx, coords);
|
||||||
let (end_x, end_y) = haystack_idx_to_coord(idx + s.len(), coords);
|
let (end_x, end_y) = haystack_idx_to_coord(idx + s.len(), coords);
|
||||||
@ -166,18 +174,25 @@ impl Tab for LocalTab {
|
|||||||
grapheme_idx,
|
grapheme_idx,
|
||||||
stable_row,
|
stable_row,
|
||||||
});
|
});
|
||||||
haystack.push_str(cell.str());
|
|
||||||
|
let s = cell.str();
|
||||||
|
if let Pattern::CaseInSensitiveString(_) = &pattern {
|
||||||
|
// normalize the case so we match everything lowercase
|
||||||
|
haystack.push_str(&s.to_lowercase());
|
||||||
|
} else {
|
||||||
|
haystack.push_str(cell.str());
|
||||||
|
}
|
||||||
wrapped = cell.attrs().wrapped();
|
wrapped = cell.attrs().wrapped();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !wrapped {
|
if !wrapped {
|
||||||
collect_matches(&mut results, pattern, &haystack, &coords);
|
collect_matches(&mut results, &pattern, &haystack, &coords);
|
||||||
haystack.clear();
|
haystack.clear();
|
||||||
coords.clear();
|
coords.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collect_matches(&mut results, pattern, &haystack, &coords);
|
collect_matches(&mut results, &pattern, &haystack, &coords);
|
||||||
results
|
results
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ fn schedule_next_paste(paste: &Arc<Mutex<Paste>>) {
|
|||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub enum Pattern {
|
pub enum Pattern {
|
||||||
CaseSensitiveString(String),
|
CaseSensitiveString(String),
|
||||||
|
CaseInSensitiveString(String),
|
||||||
// Regex(regex::Regex),
|
// Regex(regex::Regex),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ impl std::ops::Deref for Pattern {
|
|||||||
fn deref(&self) -> &String {
|
fn deref(&self) -> &String {
|
||||||
match self {
|
match self {
|
||||||
Pattern::CaseSensitiveString(s) => s,
|
Pattern::CaseSensitiveString(s) => s,
|
||||||
|
Pattern::CaseInSensitiveString(s) => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,6 +66,7 @@ impl std::ops::DerefMut for Pattern {
|
|||||||
fn deref_mut(&mut self) -> &mut String {
|
fn deref_mut(&mut self) -> &mut String {
|
||||||
match self {
|
match self {
|
||||||
Pattern::CaseSensitiveString(s) => s,
|
Pattern::CaseSensitiveString(s) => s,
|
||||||
|
Pattern::CaseInSensitiveString(s) => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +101,7 @@ pub trait Tab: Downcast {
|
|||||||
/// Performs a search.
|
/// Performs a search.
|
||||||
/// If the result is empty then there are no matches.
|
/// If the result is empty then there are no matches.
|
||||||
/// Otherwise, the result shall contain all possible matches.
|
/// Otherwise, the result shall contain all possible matches.
|
||||||
fn search(&self, _pattern: &Pattern) -> Vec<SearchResult> {
|
fn search(&self, _pattern: Pattern) -> Vec<SearchResult> {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user