Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Hide cursors by default, but show some
Conrad Irwinef0432da0db2
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex d8918d3f297..6b449f4e73b 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -569,6 +569,8 @@ pub struct Editor {project: Option<Model<Project>>,collaboration_hub: Option<Box<dyn CollaborationHub>>,blink_manager: Model<BlinkManager>,+ recently_focused: bool,+ hovered_selections: HashSet<(ReplicaId, usize)>,pub show_local_selections: bool,mode: EditorMode,show_gutter: bool,@@ -1808,6 +1810,8 @@ impl Editor {pixel_position_of_newest_cursor: None,gutter_width: Default::default(),style: None,+ recently_focused: false,+ hovered_selections: Default::default(),editor_actions: Default::default(),show_copilot_suggestions: mode == EditorMode::Full,_subscriptions: vec![@@ -9196,6 +9200,16 @@ impl Editor {cx.focus(&rename_editor_focus_handle);} else {self.blink_manager.update(cx, BlinkManager::enable);+ self.recently_focused = true;+ cx.spawn(|this, mut cx| async move {+ cx.background_executor().timer(Duration::from_secs(5)).await;+ this.update(&mut cx, |this, cx| {+ this.recently_focused = false;+ cx.notify()+ })+ .ok()+ })+ .detach();self.buffer.update(cx, |buffer, cx| {buffer.finalize_last_transaction(cx);if self.leader_peer_id.is_none() {diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 4e7a3bc2430..cf3b1d2f160 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -586,6 +586,32 @@ impl EditorElement {}}+ fn update_visible_cursor(+ editor: &mut Editor,+ point: DisplayPoint,+ cx: &mut ViewContext<Editor>,+ ) {+ let snapshot = editor.snapshot(cx);+ if let Some(hub) = editor.collaboration_hub() {+ let range = if point.column() > 0 {+ DisplayPoint::new(point.row(), point.column() - 1)..point+ } else {+ point..DisplayPoint::new(point.row(), point.column() + 1)+ };+ let range = snapshot+ .buffer_snapshot+ .anchor_at(range.start.to_point(&snapshot.display_snapshot), Bias::Left)+ ..snapshot+ .buffer_snapshot+ .anchor_at(range.end.to_point(&snapshot.display_snapshot), Bias::Right);+ for selection in snapshot.remote_selections_in_range(&range, hub, cx) {+ let key = (selection.replica_id, selection.selection.id);+ editor.hovered_selections.insert(key);+ }+ }+ editor.hovered_selections.clear();+ }+fn paint_background(&self,gutter_bounds: Bounds<Pixels>,@@ -1962,6 +1988,7 @@ impl EditorElement {if Some(selection.peer_id) == editor.leader_peer_id {continue;}+ let id = (selection.replica_id, selection.selection.id);remote_selections.entry(selection.replica_id)@@ -1974,7 +2001,11 @@ impl EditorElement {&snapshot.display_snapshot,false,false,- selection.user_name,+ if editor.recently_focused || editor.hovered_selections.contains(&id) {+ selection.user_name+ } else {+ None+ },));}