1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 21:32:13 +03:00

fix an issue where ScrollToPrompt got confused by two prompts on same line

refs: https://github.com/wez/wezterm/issues/1121
This commit is contained in:
Wez Furlong 2022-01-17 22:47:51 -07:00
parent 2c44abc700
commit c930e333c4
2 changed files with 22 additions and 7 deletions

View File

@ -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

View File

@ -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<SemanticZone>,
zones: Vec<StableRowIndex>,
}
#[derive(Default, Clone)]
@ -1734,7 +1734,7 @@ impl TermWindow {
}
/// Returns the Prompt semantic zones
fn get_semantic_prompt_zones(&mut self, pane: &Rc<dyn Pane>) -> &[SemanticZone] {
fn get_semantic_prompt_zones(&mut self, pane: &Rc<dyn Pane>) -> &[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<StableRowIndex> = 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.
// <https://github.com/wez/wezterm/issues/1121>
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() {