Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make read only buffers feel more read only
Conrad Irwin6877bd4969d2
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 1a0ccba03ce..e3b0e9874bf 100644--- a/crates/editor/src/editor.rs+++ b/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>) {diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 2b5c97bac5b..368fc4b7ca8 100644--- a/crates/editor/src/element.rs+++ b/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 {diff --git a/crates/gpui/src/color.rs b/crates/gpui/src/color.rsindex df16d2c0b56..dc0f5055e70 100644--- a/crates/gpui/src/color.rs+++ b/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) {diff --git a/crates/theme/src/styles/players.rs b/crates/theme/src/styles/players.rsindex 9f9b837e47b..089de247230 100644--- a/crates/theme/src/styles/players.rs+++ b/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]