From 15c4c4a3080284b82ce91da1ad1f49fd9ac91df5 Mon Sep 17 00:00:00 2001 From: Philipp Schaffrath Date: Fri, 19 Apr 2024 00:20:23 +0200 Subject: [PATCH] wayland: Fix input_handler out of range access (#10724) The wayland implementation takes an input handler from the state, but only puts it back if the event was an IME key. I flipped the logic to ensure it's always put back. This should fix both: - #10344 - #10652 Release Notes: - Fixed input_handler out of range access ([#10344](https://github.com/zed-industries/zed/issues/10344), [#10652](https://github.com/zed-industries/zed/issues/10652)). --- crates/gpui/src/platform/linux/wayland/window.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/gpui/src/platform/linux/wayland/window.rs b/crates/gpui/src/platform/linux/wayland/window.rs index b8417593d6..41bbd09e7e 100644 --- a/crates/gpui/src/platform/linux/wayland/window.rs +++ b/crates/gpui/src/platform/linux/wayland/window.rs @@ -481,13 +481,12 @@ impl WaylandWindowStatePtr { } } if let PlatformInput::KeyDown(event) = input { - let mut state = self.state.borrow_mut(); - if let Some(mut input_handler) = state.input_handler.take() { - if let Some(ime_key) = &event.keystroke.ime_key { + if let Some(ime_key) = &event.keystroke.ime_key { + let mut state = self.state.borrow_mut(); + if let Some(mut input_handler) = state.input_handler.take() { drop(state); input_handler.replace_text_in_range(None, ime_key); - let mut state = self.state.borrow_mut(); - state.input_handler = Some(input_handler); + self.state.borrow_mut().input_handler = Some(input_handler); } } }