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.
This commit is contained in:
Finn Evers
2025-11-19 23:40:54 +00:00
committed by GitHub
parent f2f40a5099
commit 1fab43d467
2 changed files with 21 additions and 4 deletions
+2 -2
View File
@@ -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(
+19 -2
View File
@@ -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<SyntaxTheme>) -> Self {
fn new(
container_style: &StyleRefinement,
base_text_style: TextStyle,
syntax_theme: Arc<SyntaxTheme>,
) -> 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(),