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.

markdown: Round inline code backgrounds across all markdown surfaces (#63272)

María Craig9e9b13c5b6e3
diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs
index 62368c5db46..53c1aadd884 100644
--- a/crates/markdown/src/markdown.rs
+++ b/crates/markdown/src/markdown.rs
@@ -111,7 +111,6 @@ pub struct MarkdownStyle {
pub code_block: StyleRefinement,
pub code_block_overflow_x_scroll: bool,
pub inline_code: TextStyleRefinement,
- pub inline_code_corner_radius: Pixels,
pub block_quote: TextStyleRefinement,
pub link: TextStyleRefinement,
pub link_callback: Option<LinkStyleCallback>,
@@ -143,7 +142,6 @@ impl Default for MarkdownStyle {
code_block: Default::default(),
code_block_overflow_x_scroll: false,
inline_code: Default::default(),
- inline_code_corner_radius: px(0.),
block_quote: Default::default(),
link: Default::default(),
link_callback: None,
@@ -360,7 +358,6 @@ impl MarkdownStyle {
self.inline_code.color = Some(colors.text);
self.inline_code.font_size = Some(rems(0.875).into());
- self.inline_code_corner_radius = px(4.);
self.link.background_color = None;
@@ -1782,11 +1779,7 @@ impl MarkdownElement {
};
let mut code_style = self.style.inline_code.clone();
- let chip_background = if self.style.inline_code_corner_radius > px(0.) {
- code_style.background_color.take()
- } else {
- None
- };
+ let chip_background = code_style.background_color.take();
if let Some(url) = link_url {
builder.push_link(url.clone(), range.clone());
@@ -2497,7 +2490,6 @@ impl Element for MarkdownElement {
self.style.base_text_style.clone(),
self.style.syntax.clone(),
highlights,
- self.style.inline_code_corner_radius,
);
let (parsed_markdown, images, active_root_block, render_mermaid_diagrams, mermaid_state) = {
let markdown = self.markdown.read(cx);
@@ -3590,7 +3582,6 @@ struct MarkdownElementBuilder {
table: TableState,
syntax_theme: Arc<SyntaxTheme>,
highlights: MarkdownHighlights,
- code_chip_corner_radius: Pixels,
}
struct MarkdownHighlights {
@@ -3687,7 +3678,6 @@ impl MarkdownElementBuilder {
base_text_style: TextStyle,
syntax_theme: Arc<SyntaxTheme>,
highlights: MarkdownHighlights,
- code_chip_corner_radius: Pixels,
) -> Self {
Self {
div_stack: vec![{
@@ -3711,7 +3701,6 @@ impl MarkdownElementBuilder {
table: TableState::default(),
syntax_theme,
highlights,
- code_chip_corner_radius,
}
}
@@ -4051,7 +4040,6 @@ impl MarkdownElementBuilder {
text_align: TextAlign::Left,
highlights: SmallVec::new(),
code_chips: SmallVec::new(),
- code_chip_corner_radius: px(0.),
}));
div()
.absolute()
@@ -4086,7 +4074,6 @@ impl MarkdownElementBuilder {
text_align,
highlights,
code_chips: line.code_chips.into_iter().collect(),
- code_chip_corner_radius: self.code_chip_corner_radius,
});
if rendered_line.highlights.is_empty() && rendered_line.code_chips.is_empty() {
self.rendered_lines.push(rendered_line);
@@ -4194,12 +4181,13 @@ struct RenderedLine {
highlights: SmallVec<[(Range<usize>, Hsla); 1]>,
/// Inline code chip ranges intersecting this line, in rendered indices
code_chips: SmallVec<[(Range<usize>, Hsla); 1]>,
- code_chip_corner_radius: Pixels,
}
impl RenderedLine {
/// Painted before the glyphs so the text renders on top of the chips
fn paint_code_chips(&self, window: &mut Window) {
+ const CHIP_CORNER_RADIUS: Pixels = px(4.);
+
if self.code_chips.is_empty() {
return;
}
@@ -4231,7 +4219,7 @@ impl RenderedLine {
};
window.paint_quad(quad(
chip_bounds,
- self.code_chip_corner_radius,
+ CHIP_CORNER_RADIUS,
*color,
Edges::default(),
Hsla::transparent_black(),
@@ -5358,7 +5346,6 @@ mod tests {
background_color: Some(chip_background),
..Default::default()
},
- inline_code_corner_radius: px(4.),
..Default::default()
};
@@ -5371,14 +5358,6 @@ mod tests {
("four".to_string(), chip_background)
]
);
-
- // Without a corner radius, backgrounds stay on the text runs and no
- // chips are recorded.
- let sharp_style = MarkdownStyle {
- inline_code_corner_radius: px(0.),
- ..style_with_chips()
- };
- assert_eq!(rendered_code_chips("one `two`", sharp_style, cx), vec![]);
}
fn render_markdown_with_image_resolver(