Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

WIP

Antonio Scandurra48b3a90fbf0c
diff --git a/crates/editor2/src/display_map/block_map.rs b/crates/editor2/src/display_map/block_map.rs
index 2f65903f080..05106dd2a1f 100644
--- a/crates/editor2/src/display_map/block_map.rs
+++ b/crates/editor2/src/display_map/block_map.rs
@@ -2,7 +2,7 @@ use super::{
wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot},
Highlights,
};
-use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _};
+use crate::{Anchor, Editor, EditorStyle, ExcerptId, ExcerptRange, ToPoint as _};
use collections::{Bound, HashMap, HashSet};
use gpui::{AnyElement, Pixels, ViewContext};
use language::{BufferSnapshot, Chunk, Patch, Point};
@@ -88,6 +88,7 @@ pub struct BlockContext<'a, 'b> {
pub em_width: Pixels,
pub line_height: Pixels,
pub block_id: usize,
+ pub editor_style: &'b EditorStyle,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs
index 3a5b150520c..23dfc9b9d3f 100644
--- a/crates/editor2/src/editor.rs
+++ b/crates/editor2/src/editor.rs
@@ -7796,9 +7796,35 @@ impl Editor {
position: range.start.clone(),
height: 1,
render: Arc::new({
- let editor = rename_editor.clone();
+ let rename_editor = rename_editor.clone();
move |cx: &mut BlockContext| {
- div().pl(cx.anchor_x).child(editor.clone()).render()
+ let text_style = if let Some(highlight_style) = old_highlight_id
+ .and_then(|h| h.style(&cx.editor_style.syntax))
+ {
+ cx.editor_style
+ .text
+ .clone()
+ .highlight(highlight_style)
+ .unwrap_or_else(|_| cx.editor_style.text.clone())
+ } else {
+ cx.editor_style.text.clone()
+ };
+ div().pl(cx.anchor_x).child(with_view(
+ &rename_editor,
+ |_, _| {
+ EditorElement::new(EditorStyle {
+ background: cx.theme().system().transparent,
+ local_player: cx.editor_style.local_player,
+ text: text_style,
+ scrollbar_width: cx.editor_style.scrollbar_width,
+ syntax: cx.editor_style.syntax.clone(),
+ diagnostic_style: cx
+ .editor_style
+ .diagnostic_style
+ .clone(),
+ })
+ },
+ ))
}
}),
disposition: BlockDisposition::Below,
diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs
index b8e7439ff16..5cdedd1de77 100644
--- a/crates/editor2/src/element.rs
+++ b/crates/editor2/src/element.rs
@@ -2010,6 +2010,7 @@ impl EditorElement {
gutter_width,
em_width,
block_id,
+ editor_style: &self.style,
})
}
TransformBlock::ExcerptHeader {
@@ -2658,6 +2659,12 @@ impl Element<Editor> for EditorElement {
}
}
+impl Component<Editor> for EditorElement {
+ fn render(self) -> AnyElement<Editor> {
+ AnyElement::new(self)
+ }
+}
+
// impl EditorElement {
// type LayoutState = LayoutState;
// type PaintState = ();