diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index d8918d3f29..6b449f4e73 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -569,6 +569,8 @@ pub struct Editor { project: Option>, collaboration_hub: Option>, blink_manager: Model, + 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.rs index 4e7a3bc243..cf3b1d2f16 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, + ) { + 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, @@ -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 + }, )); }