1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-13 07:22:52 +03:00

wezterm: search mode: add PageUp + PageDown

These move one page at a time, which is useful when there are a lot
of matches in a given page.

refs: https://github.com/wez/wezterm/issues/91
This commit is contained in:
Wez Furlong 2020-06-05 08:50:38 -07:00
parent 47ca722456
commit 62cd4665d2
2 changed files with 43 additions and 4 deletions

View File

@ -72,8 +72,10 @@ When the search overlay is active the behavior of wezterm changes:
the number of matches shown in the search bar
* The bottom-most match will be selected and the viewport scrolled to show the selected
text.
* `Enter` and `CTRL-P` will cause the selection to move to any prior matching text
* `CTRL-N` will cause the selection to move to any next matching text
* `Enter`, `UpArrow` and `CTRL-P` will cause the selection to move to any prior matching text
* `PageUp` will traverse to previous matches 1 page at a time.
* `CTRL-N` and `DownArrow` will cause the selection to move to any next matching text
* `PageDown` will traverse to the next matche 1 page at a time.
* `CTRL-R` will cycle through the pattern matching mode; the initial mode is case-sensitive
text matching, the next will match ignoring case and the last will match using the
[regular expression syntax described here](https://docs.rs/regex/1.3.9/regex/#syntax).

View File

@ -127,7 +127,9 @@ impl Tab for SearchOverlay {
fn key_down(&self, key: KeyCode, mods: KeyModifiers) -> anyhow::Result<()> {
match (key, mods) {
(KeyCode::Escape, KeyModifiers::NONE) => self.renderer.borrow().close(),
(KeyCode::Enter, KeyModifiers::NONE) | (KeyCode::Char('p'), KeyModifiers::CTRL) => {
(KeyCode::UpArrow, KeyModifiers::NONE)
| (KeyCode::Enter, KeyModifiers::NONE)
| (KeyCode::Char('p'), KeyModifiers::CTRL) => {
// Move to prior match
let mut r = self.renderer.borrow_mut();
if let Some(cur) = r.result_pos.as_ref() {
@ -139,7 +141,42 @@ impl Tab for SearchOverlay {
r.activate_match_number(prior);
}
}
(KeyCode::Char('n'), KeyModifiers::CTRL) => {
(KeyCode::PageUp, KeyModifiers::NONE) => {
// Skip this page of matches and move up to the first match from
// the prior page.
let dims = self.delegate.renderer().get_dimensions();
let mut r = self.renderer.borrow_mut();
if let Some(cur) = r.result_pos {
let top = r.viewport.unwrap_or(dims.physical_top);
let prior = top - dims.viewport_rows as isize;
if let Some(pos) = r
.results
.iter()
.position(|res| res.start_y > prior && res.start_y < top)
{
r.activate_match_number(pos);
} else {
r.activate_match_number(cur.saturating_sub(1));
}
}
}
(KeyCode::PageDown, KeyModifiers::NONE) => {
// Skip this page of matches and move down to the first match from
// the next page.
let dims = self.delegate.renderer().get_dimensions();
let mut r = self.renderer.borrow_mut();
if let Some(cur) = r.result_pos {
let top = r.viewport.unwrap_or(dims.physical_top);
let bottom = top + dims.viewport_rows as isize;
if let Some(pos) = r.results.iter().position(|res| res.start_y >= bottom) {
r.activate_match_number(pos);
} else {
let len = r.results.len().saturating_sub(1);
r.activate_match_number(cur.min(len));
}
}
}
(KeyCode::DownArrow, KeyModifiers::NONE) | (KeyCode::Char('n'), KeyModifiers::CTRL) => {
// Move to next match
let mut r = self.renderer.borrow_mut();
if let Some(cur) = r.result_pos.as_ref() {