Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
terminal: Fix IME candidate window not following cursor in TUI apps (#59911)
Gavin Luoc56646ffdfff
diff --git a/crates/gpui_linux/src/linux/wayland/client.rs b/crates/gpui_linux/src/linux/wayland/client.rsindex ac637d3fc46..256875bed1e 100644--- a/crates/gpui_linux/src/linux/wayland/client.rs+++ b/crates/gpui_linux/src/linux/wayland/client.rs@@ -388,7 +388,7 @@ impl WaylandClientStatePtr {pub fn update_ime_position(&self, bounds: Bounds<Pixels>) {let client = self.get_client();let state = client.borrow_mut();- if state.composing || state.text_input.is_none() || state.pre_edit_text.is_some() {+ if state.text_input.is_none() || state.pre_edit_text.is_some() {return;}diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rsindex cd0ed9241fa..b74d28593d0 100644--- a/crates/terminal_view/src/terminal_element.rs+++ b/crates/terminal_view/src/terminal_element.rs@@ -1349,7 +1349,6 @@ impl Element for TerminalElement {};let terminal_input_handler = TerminalInputHandler {- terminal: self.terminal.clone(),terminal_view: self.terminal_view.clone(),cursor_bounds: layout.ime_cursor_bounds.map(|bounds| bounds + origin),workspace: self.workspace.clone(),@@ -1510,7 +1509,6 @@ impl IntoElement for TerminalElement {}struct TerminalInputHandler {- terminal: Entity<Terminal>,terminal_view: Entity<TerminalView>,workspace: WeakEntity<Workspace>,cursor_bounds: Option<Bounds<Pixels>>,@@ -1521,22 +1519,15 @@ impl InputHandler for TerminalInputHandler {&mut self,_ignore_disabled_input: bool,_: &mut Window,- cx: &mut App,+ _cx: &mut App,) -> Option<UTF16Selection> {- if self- .terminal- .read(cx)- .last_content- .mode- .contains(Modes::ALT_SCREEN)- {- None- } else {- Some(UTF16Selection {- range: 0..0,- reversed: false,- })- }+ // Always return a valid selection for IME positioning,+ // even in ALT_SCREEN mode (fullscreen TUI apps like opencode, vim, etc.)+ // The terminal still has a cursor position that should be used for IME candidate window placement.+ Some(UTF16Selection {+ range: 0..0,+ reversed: false,+ })}fn marked_text_range(diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rsindex ea888d564cc..3b1e6db97fc 100644--- a/crates/terminal_view/src/terminal_view.rs+++ b/crates/terminal_view/src/terminal_view.rs@@ -1129,6 +1129,7 @@ fn subscribe_for_terminal_events(match event {Event::Wakeup => {cx.notify();+ window.invalidate_character_coordinates();cx.emit(Event::Wakeup);cx.emit(ItemEvent::UpdateTab);cx.emit(SearchEvent::MatchesInvalidated);