From 0c95e5a6ca01e7c1d4d2e7d772dd8b4aa5e40fa3 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 28 Sep 2023 11:37:44 -0700 Subject: [PATCH] Fix coloring of local selections when following Co-authored-by: Conrad --- crates/editor/src/element.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 0be395729f..924d66c21c 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2250,6 +2250,21 @@ impl Element for EditorElement { } if let Some(collaboration_hub) = &editor.collaboration_hub { + // When following someone, render the local selections in their color. + if let Some(leader_id) = editor.leader_peer_id { + if let Some(collaborator) = collaboration_hub.collaborators(cx).get(&leader_id) { + if let Some(participant_index) = collaboration_hub + .user_participant_indices(cx) + .get(&collaborator.user_id) + { + if let Some((local_selection_style, _)) = selections.first_mut() { + *local_selection_style = + style.selection_style_for_room_participant(participant_index.0); + } + } + } + } + let mut remote_selections = HashMap::default(); for selection in snapshot.remote_selections_in_range( &(start_anchor..end_anchor), @@ -2262,11 +2277,9 @@ impl Element for EditorElement { style.absent_selection }; - // The local selections match the leader's selections. + // Don't re-render the leader's selections, since the local selections + // match theirs. if Some(selection.peer_id) == editor.leader_peer_id { - if let Some((local_selection_style, _)) = selections.first_mut() { - *local_selection_style = selection_style; - } continue; }