Make read only buffers feel more read only

Conrad Irwin created

Change summary

crates/editor/src/editor.rs        |  3 ++-
crates/editor/src/element.rs       |  8 +++++++-
crates/gpui/src/color.rs           |  9 +++++++++
crates/theme/src/styles/players.rs | 13 +++++++++++--
4 files changed, 29 insertions(+), 4 deletions(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -8605,7 +8605,8 @@ impl Editor {
     }
 
     pub fn show_local_cursors(&self, cx: &WindowContext) -> bool {
-        self.blink_manager.read(cx).visible() && self.focus_handle.is_focused(cx)
+        (self.read_only(cx) || self.blink_manager.read(cx).visible())
+            && self.focus_handle.is_focused(cx)
     }
 
     fn on_buffer_changed(&mut self, _: Model<MultiBuffer>, cx: &mut ViewContext<Self>) {

crates/editor/src/element.rs 🔗

@@ -1901,7 +1901,13 @@ impl EditorElement {
                     layouts.push(layout);
                 }
 
-                selections.push((style.local_player, layouts));
+                let player = if editor.read_only(cx) {
+                    cx.theme().players().read_only()
+                } else {
+                    style.local_player
+                };
+
+                selections.push((player, layouts));
             }
 
             if let Some(collaboration_hub) = &editor.collaboration_hub {

crates/gpui/src/color.rs 🔗

@@ -339,6 +339,15 @@ impl Hsla {
         }
     }
 
+    pub fn grayscale(&self) -> Self {
+        Hsla {
+            h: self.h,
+            s: 0.,
+            l: self.l,
+            a: self.a,
+        }
+    }
+
     /// Fade out the color by a given factor. This factor should be between 0.0 and 1.0.
     /// Where 0.0 will leave the color unchanged, and 1.0 will completely fade out the color.
     pub fn fade_out(&mut self, factor: f32) {

crates/theme/src/styles/players.rs 🔗

@@ -1,7 +1,7 @@
-use gpui::Hsla;
+use gpui::{hsla, Hsla};
 use serde_derive::Deserialize;
 
-use crate::{amber, blue, jade, lime, orange, pink, purple, red};
+use crate::{amber, blue, gray, jade, lime, orange, pink, purple, red};
 
 #[derive(Debug, Clone, Copy, Deserialize, Default)]
 pub struct PlayerColor {
@@ -131,6 +131,15 @@ impl PlayerColors {
         *self.0.last().unwrap()
     }
 
+    pub fn read_only(&self) -> PlayerColor {
+        let local = self.local();
+        PlayerColor {
+            cursor: local.cursor.grayscale(),
+            background: local.background.grayscale(),
+            selection: local.selection.grayscale(),
+        }
+    }
+
     pub fn color_for_participant(&self, participant_index: u32) -> PlayerColor {
         let len = self.0.len() - 1;
         self.0[(participant_index as usize % len) + 1]