From c930e333c42d3772992b72b564d10118cc1c544f Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 17 Jan 2022 22:47:51 -0700 Subject: [PATCH] fix an issue where ScrollToPrompt got confused by two prompts on same line refs: https://github.com/wez/wezterm/issues/1121 --- docs/changelog.md | 1 + wezterm-gui/src/termwindow/mod.rs | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index fbca92341..7bd3b8bf4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -52,6 +52,7 @@ As features stabilize some brief notes about them will accumulate here. * Windows: latency issue with AltSnap and other window-managery things [#1013](https://github.com/wez/wezterm/issues/1013) [#1398](https://github.com/wez/wezterm/issues/1398) [#1075](https://github.com/wez/wezterm/issues/1075) [#1099](https://github.com/wez/wezterm/issues/1099) * Multiplexer sessions now propagate user vars [#1528](https://github.com/wez/wezterm/issues/1528) * Config reloads on the multiplexer server didn't cause the palette to update on the client [#1526](https://github.com/wez/wezterm/issues/1528) +* [ScrollToTop](config/lua/keyassignment/ScrollToTop.md) could get confused when there were multiple prompts on the same line [#1121](https://github.com/wez/wezterm/issues/1121) ### 20220101-133340-7edc5b5a diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 03b30cc26..d38350083 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -48,7 +48,7 @@ use termwiz::surface::SequenceNo; use wezterm_font::FontConfiguration; use wezterm_term::color::ColorPalette; use wezterm_term::input::LastMouseClick; -use wezterm_term::{Alert, SemanticZone, StableRowIndex, TerminalConfiguration}; +use wezterm_term::{Alert, StableRowIndex, TerminalConfiguration}; pub mod box_model; pub mod clipboard; @@ -142,7 +142,7 @@ impl UIItem { #[derive(Clone, Default)] pub struct SemanticZoneCache { seqno: SequenceNo, - zones: Vec, + zones: Vec, } #[derive(Default, Clone)] @@ -1734,7 +1734,7 @@ impl TermWindow { } /// Returns the Prompt semantic zones - fn get_semantic_prompt_zones(&mut self, pane: &Rc) -> &[SemanticZone] { + fn get_semantic_prompt_zones(&mut self, pane: &Rc) -> &[StableRowIndex] { let mut cache = self .semantic_zones .entry(pane.pane_id()) @@ -1742,8 +1742,22 @@ impl TermWindow { let seqno = pane.get_current_seqno(); if cache.seqno != seqno { - let mut zones = pane.get_semantic_zones().unwrap_or_else(|_| vec![]); - zones.retain(|zone| zone.semantic_type == wezterm_term::SemanticType::Prompt); + let zones = pane.get_semantic_zones().unwrap_or_else(|_| vec![]); + let mut zones: Vec = zones + .into_iter() + .filter_map(|zone| { + if zone.semantic_type == wezterm_term::SemanticType::Prompt { + Some(zone.start_y) + } else { + None + } + }) + .collect(); + // dedup to avoid issues where both left and right prompts are + // defined: we only care if there were 1+ prompts on a line, + // not about how many prompts are on a line. + // + zones.dedup(); cache.zones = zones; cache.seqno = seqno; } @@ -1761,14 +1775,14 @@ impl TermWindow { .unwrap_or(dims.physical_top); let zone = { let zones = self.get_semantic_prompt_zones(&pane); - let idx = match zones.binary_search_by(|zone| zone.start_y.cmp(&position)) { + let idx = match zones.binary_search(&position) { Ok(idx) | Err(idx) => idx, }; let idx = ((idx as isize) + amount).max(0) as usize; zones.get(idx).cloned() }; if let Some(zone) = zone { - self.set_viewport(pane.pane_id(), Some(zone.start_y), dims); + self.set_viewport(pane.pane_id(), Some(zone), dims); } if let Some(win) = self.window.as_ref() {