Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Blink cursors only in the focused editor (#61086)

Daan De Meyer7d07d39f19d1
diff --git a/crates/editor/src/blink_manager.rs b/crates/editor/src/blink_manager.rs
index f265744de33..f6ebae5a917 100644
--- a/crates/editor/src/blink_manager.rs
+++ b/crates/editor/src/blink_manager.rs
@@ -112,4 +112,9 @@ impl BlinkManager {
pub fn visible(&self) -> bool {
self.visible
}
+
+ #[cfg(test)]
+ pub(crate) fn enabled(&self) -> bool {
+ self.enabled
+ }
}
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 06c2913c5dd..8cbbba449e8 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -2416,16 +2416,6 @@ impl Editor {
cx.observe_global_in::<SettingsStore>(window, Self::settings_changed),
cx.observe_global_in::<GlobalTheme>(window, Self::theme_changed),
observe_buffer_font_size_adjustment(cx, |_, cx| cx.notify()),
- cx.observe_window_activation(window, |editor, window, cx| {
- let active = window.is_window_active();
- editor.blink_manager.update(cx, |blink_manager, cx| {
- if active {
- blink_manager.enable(cx);
- } else {
- blink_manager.disable(cx);
- }
- });
- }),
]
})
.unwrap_or_default(),
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index 3efc8a5b291..516797a740d 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -2485,6 +2485,45 @@ fn test_beginning_of_line_single_line_editor(cx: &mut TestAppContext) {
});
}
+#[gpui::test]
+fn test_only_focused_editor_blinks_across_window_activation(cx: &mut TestAppContext) {
+ init_test(cx, |_| {});
+
+ let window = cx.add_window(|window, cx| Editor::single_line(window, cx));
+ let unfocused_editor = window
+ .update(cx, |focused_editor, window, cx| {
+ window.focus(&focused_editor.focus_handle(cx), cx);
+ let unfocused_editor = cx.new(|cx| Editor::single_line(window, cx));
+ window.activate_window();
+ unfocused_editor
+ })
+ .unwrap();
+ let focused_editor = window.root(cx).unwrap();
+ let cx = &mut VisualTestContext::from_window(*window, cx);
+ cx.run_until_parked();
+
+ cx.update(|window, cx| {
+ assert!(window.is_window_active());
+ assert!(focused_editor.read(cx).blink_manager.read(cx).enabled());
+ assert!(!unfocused_editor.read(cx).blink_manager.read(cx).enabled());
+ });
+
+ cx.deactivate_window();
+ cx.update(|window, cx| {
+ assert!(!window.is_window_active());
+ assert!(!focused_editor.read(cx).blink_manager.read(cx).enabled());
+ assert!(!unfocused_editor.read(cx).blink_manager.read(cx).enabled());
+ });
+
+ cx.update(|window, _| window.activate_window());
+ cx.run_until_parked();
+ cx.update(|window, cx| {
+ assert!(window.is_window_active());
+ assert!(focused_editor.read(cx).blink_manager.read(cx).enabled());
+ assert!(!unfocused_editor.read(cx).blink_manager.read(cx).enabled());
+ });
+}
+
#[gpui::test]
fn test_beginning_end_of_line_ignore_soft_wrap(cx: &mut TestAppContext) {
init_test(cx, |_| {});