1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 03:39:16 +03:00

wezterm: search add regex as an pattern option

This commit is contained in:
Wez Furlong 2020-05-29 09:24:30 -07:00
parent 8b92fbdde3
commit 584ced1944
3 changed files with 28 additions and 10 deletions

View File

@ -155,8 +155,9 @@ impl Tab for SearchOverlay {
// CTRL-r cycles through pattern match types
let mut r = self.renderer.borrow_mut();
let pattern = match &r.pattern {
Pattern::CaseInSensitiveString(s) => Pattern::CaseSensitiveString(s.clone()),
Pattern::CaseSensitiveString(s) => Pattern::CaseInSensitiveString(s.clone()),
Pattern::CaseInSensitiveString(s) => Pattern::Regex(s.clone()),
Pattern::Regex(s) => Pattern::CaseSensitiveString(s.clone()),
};
r.pattern = pattern;
r.update_search();
@ -352,6 +353,7 @@ impl Renderable for SearchRenderable {
let mode = &match self.pattern {
Pattern::CaseSensitiveString(_) => "case-sensitive",
Pattern::CaseInSensitiveString(_) => "ignore-case",
Pattern::Regex(_) => "regex",
};
line.overlay_text_with_attribute(
0,

View File

@ -156,11 +156,21 @@ impl Tab for LocalTab {
end_y,
});
}
} /*
Pattern::Regex(r) => {
// TODO
}
*/
}
Pattern::Regex(r) => {
if let Ok(re) = regex::Regex::new(r) {
for m in re.find_iter(haystack) {
let (start_x, start_y) = haystack_idx_to_coord(m.start(), coords);
let (end_x, end_y) = haystack_idx_to_coord(m.end(), coords);
results.push(SearchResult {
start_x,
start_y,
end_x,
end_y,
});
}
}
}
}
}
@ -186,9 +196,13 @@ impl Tab for LocalTab {
}
if !wrapped {
collect_matches(&mut results, &pattern, &haystack, &coords);
haystack.clear();
coords.clear();
if let Pattern::Regex(_) = &pattern {
haystack.push('\n');
} else {
collect_matches(&mut results, &pattern, &haystack, &coords);
haystack.clear();
coords.clear();
}
}
}

View File

@ -49,7 +49,7 @@ fn schedule_next_paste(paste: &Arc<Mutex<Paste>>) {
pub enum Pattern {
CaseSensitiveString(String),
CaseInSensitiveString(String),
// Regex(regex::Regex),
Regex(String),
}
impl std::ops::Deref for Pattern {
@ -58,6 +58,7 @@ impl std::ops::Deref for Pattern {
match self {
Pattern::CaseSensitiveString(s) => s,
Pattern::CaseInSensitiveString(s) => s,
Pattern::Regex(s) => s,
}
}
}
@ -67,6 +68,7 @@ impl std::ops::DerefMut for Pattern {
match self {
Pattern::CaseSensitiveString(s) => s,
Pattern::CaseInSensitiveString(s) => s,
Pattern::Regex(s) => s,
}
}
}