From ea1f5331c89a84d5ae91e8dbb7d81b04587f874a Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 16 Jul 2025 14:01:46 +0800 Subject: [PATCH] input: Hide cursor and selection when window is deactivated. (#1066) --- crates/ui/src/input/element.rs | 6 ++++-- crates/ui/src/input/state.rs | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index f7182314..a1645676 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -900,8 +900,10 @@ impl Element for TextElement { } // Paint selections - if let Some(path) = prepaint.selection_path.take() { - window.paint_path(path, cx.theme().selection); + if window.is_window_active() { + if let Some(path) = prepaint.selection_path.take() { + window.paint_path(path, cx.theme().selection); + } } // Paint text diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index 9cb56ac5..f1726269 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -1963,7 +1963,9 @@ impl InputState { /// Returns the true to let InputElement to render cursor, when Input is focused and current BlinkCursor is visible. pub(crate) fn show_cursor(&self, window: &Window, cx: &App) -> bool { - self.focus_handle.is_focused(window) && self.blink_cursor.read(cx).visible() + self.focus_handle.is_focused(window) + && self.blink_cursor.read(cx).visible() + && window.is_window_active() } fn on_focus(&mut self, _: &mut Window, cx: &mut Context) {