From 1fab43d467c3e610bd72cfb94ac12d09d791f397 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Thu, 20 Nov 2025 00:40:54 +0100 Subject: [PATCH] Allow styling the container of markdown elements (#43107) Closes #43033 Release Notes: - FIxed an issue where the padding on info popovers would overlay text when the content was scrollable. --- crates/editor/src/hover_popover.rs | 4 ++-- crates/markdown/src/markdown.rs | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index ef16fc92d847763ecbc764c3913266fd84a26006..5f831341bab2a4e37410a1e3e168bcf72bba93a8 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -893,7 +893,6 @@ impl InfoPopover { *keyboard_grace = false; cx.stop_propagation(); }) - .p_2() .when_some(self.parsed_content.clone(), |this, markdown| { this.child( div() @@ -909,7 +908,8 @@ impl InfoPopover { copy_button_on_hover: false, border: false, }) - .on_url_click(open_markdown_url), + .on_url_click(open_markdown_url) + .p_2(), ), ) .custom_scrollbars( diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs index 9a1596092ae0497fe2d45a1d756a34e81d601b7c..1de6d494ffbf445ca8ee3df9d1e83b5575f8224e 100644 --- a/crates/markdown/src/markdown.rs +++ b/crates/markdown/src/markdown.rs @@ -54,6 +54,7 @@ pub struct HeadingLevelStyles { #[derive(Clone)] pub struct MarkdownStyle { pub base_text_style: TextStyle, + pub container_style: StyleRefinement, pub code_block: StyleRefinement, pub code_block_overflow_x_scroll: bool, pub inline_code: TextStyleRefinement, @@ -74,6 +75,7 @@ impl Default for MarkdownStyle { fn default() -> Self { Self { base_text_style: Default::default(), + container_style: Default::default(), code_block: Default::default(), code_block_overflow_x_scroll: false, inline_code: Default::default(), @@ -748,6 +750,12 @@ impl MarkdownElement { } } +impl Styled for MarkdownElement { + fn style(&mut self) -> &mut StyleRefinement { + &mut self.style.container_style + } +} + impl Element for MarkdownElement { type RequestLayoutState = RenderedMarkdown; type PrepaintState = Hitbox; @@ -768,6 +776,7 @@ impl Element for MarkdownElement { cx: &mut App, ) -> (gpui::LayoutId, Self::RequestLayoutState) { let mut builder = MarkdownElementBuilder::new( + &self.style.container_style, self.style.base_text_style.clone(), self.style.syntax.clone(), ); @@ -1441,9 +1450,17 @@ struct ListStackEntry { } impl MarkdownElementBuilder { - fn new(base_text_style: TextStyle, syntax_theme: Arc) -> Self { + fn new( + container_style: &StyleRefinement, + base_text_style: TextStyle, + syntax_theme: Arc, + ) -> Self { Self { - div_stack: vec![div().debug_selector(|| "inner".into()).into()], + div_stack: vec![{ + let mut base_div = div(); + base_div.style().refine(container_style); + base_div.debug_selector(|| "inner".into()).into() + }], rendered_lines: Vec::new(), pending_line: PendingLine::default(), rendered_links: Vec::new(),