From 89f202357748217cdfe5dea933c5043a219e5fb5 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 5 Jan 2020 15:07:00 -0800 Subject: [PATCH] mux: invalidate StableRowIndex 0..rows when switching alt screen We would leave a copy of the alt screen lines at the top of the scrollback. This commit ensures that those lines are marked dirty and that the dirty bits are propagated to the client to invalidate its cache. --- src/server/listener.rs | 7 +++++++ term/src/terminalstate.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/server/listener.rs b/src/server/listener.rs index 75520a973..884216e08 100644 --- a/src/server/listener.rs +++ b/src/server/listener.rs @@ -394,6 +394,13 @@ fn maybe_push_tab_changes( ) { dirty_rows.add(idx); } + // Make sure we pick up "damage" done by switching between alt and primary screen + for idx in tab + .renderer() + .get_dirty_lines(0..dims.viewport_rows as StableRowIndex) + { + dirty_rows.add(idx); + } let dirty_lines = dirty_rows.iter().cloned().collect(); diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index ab1ed8bce..ddbc2eb70 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -125,10 +125,23 @@ impl ScreenOrAlt { pub fn activate_alt_screen(&mut self) { self.alt_screen_is_active = true; + self.dirty_top_phys_rows(); } pub fn activate_primary_screen(&mut self) { self.alt_screen_is_active = false; + self.dirty_top_phys_rows(); + } + + // When switching between alt and primary screen, we implicitly change + // the content associated with StableRowIndex 0..num_rows. The muxer + // use case needs to know to invalidate its cache, so we mark those rows + // as dirty. + fn dirty_top_phys_rows(&mut self) { + let num_rows = self.screen.physical_rows; + for line_idx in 0..num_rows { + self.screen.line_mut(line_idx).set_dirty(); + } } pub fn is_alt_screen_active(&self) -> bool {