From 0936aa6e8d319094c63ea8a79715c732b0fd4902 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 9 May 2021 20:44:14 +0000 Subject: Fix unnecessary redraws due to hint highlighting When the mouse cursor is moved by at least one cell, an update to the highlighted hints is triggered automatically. Previously this would always update the hints and redraw Alacritty regardless of the actualy change to the hint highlighting. By checking if the hint highlighting has actually changed, pointless redraws can be prevented. This is especially helpful since mouse motions often generate a lot of hint re-computations. --- alacritty/src/display/mod.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'alacritty/src/display/mod.rs') diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index 810d20f3..0947ab7e 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -657,26 +657,31 @@ impl Display { } /// Update the mouse/vi mode cursor hint highlighting. + /// + /// This will return whether the highlighted hints changed. pub fn update_highlighted_hints( &mut self, term: &Term, config: &Config, mouse: &Mouse, modifiers: ModifiersState, - ) { + ) -> bool { // Update vi mode cursor hint. - if term.mode().contains(TermMode::VI) { + let vi_highlighted_hint = if term.mode().contains(TermMode::VI) { let mods = ModifiersState::all(); let point = term.vi_mode_cursor.point; - self.vi_highlighted_hint = hint::highlighted_at(&term, config, point, mods); + hint::highlighted_at(&term, config, point, mods) } else { - self.vi_highlighted_hint = None; - } + None + }; + let mut dirty = vi_highlighted_hint != self.vi_highlighted_hint; + self.vi_highlighted_hint = vi_highlighted_hint; // Abort if mouse highlighting conditions are not met. if !mouse.inside_text_area || !term.selection.as_ref().map_or(true, Selection::is_empty) { + dirty |= self.highlighted_hint.is_some(); self.highlighted_hint = None; - return; + return dirty; } // Find highlighted hint at mouse position. @@ -694,7 +699,10 @@ impl Display { } } + dirty |= self.highlighted_hint != highlighted_hint; self.highlighted_hint = highlighted_hint; + + dirty } /// Format search regex to account for the cursor and fullwidth characters. -- cgit