From 62cd4665d2ac0e1c7cd277cc2bb712b6cd88955a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 5 Jun 2020 08:50:38 -0700 Subject: [PATCH] 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 --- docs/scrollback.markdown | 6 +++-- src/frontend/gui/overlay/search.rs | 41 ++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/docs/scrollback.markdown b/docs/scrollback.markdown index b4c289236..25d24df72 100644 --- a/docs/scrollback.markdown +++ b/docs/scrollback.markdown @@ -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). diff --git a/src/frontend/gui/overlay/search.rs b/src/frontend/gui/overlay/search.rs index 6d71624e3..e2b2d5ce8 100644 --- a/src/frontend/gui/overlay/search.rs +++ b/src/frontend/gui/overlay/search.rs @@ -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() {