diff options
author | Christian Duerr <contact@christianduerr.com> | 2023-11-03 05:50:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-03 04:50:45 +0000 |
commit | 46f8e39880592edb47f9b54f3f34ebbcfaa01c61 (patch) | |
tree | e87d4a275a53f366afdb8af2a92e44f7c7c54e57 | |
parent | 609499640f4c45ac6ff1f7c7e1b100dea3e88858 (diff) | |
download | alacritty-46f8e39880592edb47f9b54f3f34ebbcfaa01c61.tar.gz alacritty-46f8e39880592edb47f9b54f3f34ebbcfaa01c61.zip |
Fix crash when leaving search after resize
This fixes a crash which could occur when leaving search with a visible
match after shrinking the terminal height to be lower than the original
line the focused match was in.
Closes #7054.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/display/mod.rs | 9 | ||||
-rw-r--r-- | alacritty/src/event.rs | 5 | ||||
-rw-r--r-- | alacritty/src/window_context.rs | 12 |
4 files changed, 16 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 80abac43..83779473 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `Command` modifier persisting after `Cmd + Tab` on macOS - Crash on exit when using NVIDIA binary drivers on Wayland - `window.startup_mode` applied to window again when creating new tab +- Crash when leaving search after resize ### Removed diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index 7380e8c3..dfe2809f 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -598,7 +598,7 @@ impl Display { terminal: &mut Term<T>, pty_resize_handle: &mut dyn OnResize, message_buffer: &MessageBuffer, - search_active: bool, + search_state: &mut SearchState, config: &UiConfig, ) where T: EventListener, @@ -643,6 +643,7 @@ impl Display { ); // Update number of column/lines in the viewport. + let search_active = search_state.history_index.is_some(); let message_bar_lines = message_buffer.message().map_or(0, |m| m.text(&new_size).len()); let search_lines = usize::from(search_active); new_size.reserve_lines(message_bar_lines + search_lines); @@ -658,10 +659,14 @@ impl Display { // Resize terminal. terminal.resize(new_size); - // Queue renderer update if terminal dimensions/padding changed. + // Check if dimensions have changed. if new_size != self.size_info { + // Queue renderer update. let renderer_update = self.pending_renderer_update.get_or_insert(Default::default()); renderer_update.resize = true; + + // Clear focused search match. + search_state.clear_focused_match(); } self.size_info = new_size; } diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 281bcace..beab7c74 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -154,6 +154,11 @@ impl SearchState { self.focused_match.as_ref() } + /// Clear the focused match. + pub fn clear_focused_match(&mut self) { + self.focused_match = None; + } + /// Active search dfas. pub fn dfas(&mut self) -> Option<&mut RegexSearch> { self.dfas.as_mut() diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index a80aecca..d2f7ffd4 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -480,7 +480,7 @@ impl WindowContext { &mut self.display, &mut self.notifier, &self.message_buffer, - &self.search_state, + &mut self.search_state, old_is_searching, &self.config, ); @@ -546,7 +546,7 @@ impl WindowContext { display: &mut Display, notifier: &mut Notifier, message_buffer: &MessageBuffer, - search_state: &SearchState, + search_state: &mut SearchState, old_is_searching: bool, config: &UiConfig, ) { @@ -559,13 +559,7 @@ impl WindowContext { search_state.direction == Direction::Left }; - display.handle_update( - terminal, - notifier, - message_buffer, - search_state.history_index.is_some(), - config, - ); + display.handle_update(terminal, notifier, message_buffer, search_state, config); let new_is_searching = search_state.history_index.is_some(); if !old_is_searching && new_is_searching { |