Only blink local cursors

Nathan Sobo created

Change summary

gpui/src/presenter.rs     |  8 ++++++++
zed/src/editor.rs         | 14 +++++++-------
zed/src/editor/element.rs |  3 ++-
3 files changed, 17 insertions(+), 8 deletions(-)

Detailed changes

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<usize, ElementBox>,
     dispatched_actions: Vec<DispatchDirective>,

zed/src/editor.rs 🔗

@@ -305,7 +305,7 @@ pub struct Editor {
     build_style: Rc<RefCell<dyn FnMut(&mut MutableAppContext) -> EditorStyle>>,
     settings: watch::Receiver<Settings>,
     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>) {
-        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<Self>) {
         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<Buffer>, cx: &mut ViewContext<Self>) {
@@ -2483,7 +2483,7 @@ impl View for Editor {
 
     fn on_blur(&mut self, cx: &mut ViewContext<Self>) {
         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();
         });

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 =