From 9691267dc8e7377086b2c5ebe7ab5e16fc6e65d9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 17 Sep 2021 16:17:47 -0700 Subject: [PATCH] Only blink local cursors --- gpui/src/presenter.rs | 8 ++++++++ zed/src/editor.rs | 14 +++++++------- zed/src/editor/element.rs | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gpui/src/presenter.rs b/gpui/src/presenter.rs index b2fa59b848aa2bb3ca53c9e5565104a6186bb1dc..2062397e9e6547dbe4ea9083485a8b8c0a519475 100644 --- a/gpui/src/presenter.rs +++ b/gpui/src/presenter.rs @@ -286,6 +286,14 @@ impl<'a> PaintContext<'a> { } } +impl<'a> Deref for PaintContext<'a> { + type Target = AppContext; + + fn deref(&self) -> &Self::Target { + self.app + } +} + pub struct EventContext<'a> { rendered_views: &'a mut HashMap, dispatched_actions: Vec, diff --git a/zed/src/editor.rs b/zed/src/editor.rs index 1b0eb4852b8e528c03adcaac7aaaec9498f18b5e..98f0b4a0231e8d2cfba9eab21f2a88d72ff602e0 100644 --- a/zed/src/editor.rs +++ b/zed/src/editor.rs @@ -305,7 +305,7 @@ pub struct Editor { build_style: Rc EditorStyle>>, settings: watch::Receiver, focused: bool, - cursors_visible: bool, + show_local_cursors: bool, blink_epoch: usize, blinking_paused: bool, mode: EditorMode, @@ -416,7 +416,7 @@ impl Editor { autoscroll_requested: false, settings, focused: false, - cursors_visible: false, + show_local_cursors: false, blink_epoch: 0, blinking_paused: false, mode: EditorMode::Full, @@ -2253,7 +2253,7 @@ impl Editor { } fn pause_cursor_blinking(&mut self, cx: &mut ViewContext) { - self.cursors_visible = true; + self.show_local_cursors = true; cx.notify(); let epoch = self.next_blink_epoch(); @@ -2278,7 +2278,7 @@ impl Editor { fn blink_cursors(&mut self, epoch: usize, cx: &mut ViewContext) { if epoch == self.blink_epoch && self.focused && !self.blinking_paused { - self.cursors_visible = !self.cursors_visible; + self.show_local_cursors = !self.show_local_cursors; cx.notify(); let epoch = self.next_blink_epoch(); @@ -2295,8 +2295,8 @@ impl Editor { } } - pub fn cursors_visible(&self) -> bool { - self.cursors_visible + pub fn show_local_cursors(&self) -> bool { + self.show_local_cursors } fn on_buffer_changed(&mut self, _: ModelHandle, cx: &mut ViewContext) { @@ -2483,7 +2483,7 @@ impl View for Editor { fn on_blur(&mut self, cx: &mut ViewContext) { self.focused = false; - self.cursors_visible = false; + self.show_local_cursors = false; self.buffer.update(cx, |buffer, cx| { buffer.set_active_selection_set(None, cx).unwrap(); }); diff --git a/zed/src/editor/element.rs b/zed/src/editor/element.rs index 0912265099191d2aacabaf95bfdaec7d0124c01a..7c65b1a22d19d498ffd6f58df4db81a78d5fdb82 100644 --- a/zed/src/editor/element.rs +++ b/zed/src/editor/element.rs @@ -269,6 +269,7 @@ impl EditorElement { let view = self.view(cx.app); let settings = self.view(cx.app).settings.borrow(); let theme = &settings.theme.editor; + let local_replica_id = view.replica_id(cx); let scroll_position = layout.snapshot.scroll_position(); let start_row = scroll_position.y() as u32; let scroll_top = scroll_position.y() * layout.line_height; @@ -338,7 +339,7 @@ impl EditorElement { selection.paint(bounds, cx.scene); } - if view.cursors_visible() { + if view.show_local_cursors() || *replica_id != local_replica_id { let cursor_position = selection.end; if (start_row..end_row).contains(&cursor_position.row()) { let cursor_row_layout =