Hide cursors by default, but show some

This commit is contained in:
Conrad Irwin 2024-01-17 10:14:20 -07:00
parent 0ca9f286c6
commit ef0432da0d
2 changed files with 46 additions and 1 deletions

View File

@ -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() {

View File

@ -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
},
));
}