Skip to content

Commit 1fab43d

Browse files
authored
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.
1 parent f2f40a5 commit 1fab43d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

crates/editor/src/hover_popover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,6 @@ impl InfoPopover {
893893
*keyboard_grace = false;
894894
cx.stop_propagation();
895895
})
896-
.p_2()
897896
.when_some(self.parsed_content.clone(), |this, markdown| {
898897
this.child(
899898
div()
@@ -909,7 +908,8 @@ impl InfoPopover {
909908
copy_button_on_hover: false,
910909
border: false,
911910
})
912-
.on_url_click(open_markdown_url),
911+
.on_url_click(open_markdown_url)
912+
.p_2(),
913913
),
914914
)
915915
.custom_scrollbars(

crates/markdown/src/markdown.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct HeadingLevelStyles {
5454
#[derive(Clone)]
5555
pub struct MarkdownStyle {
5656
pub base_text_style: TextStyle,
57+
pub container_style: StyleRefinement,
5758
pub code_block: StyleRefinement,
5859
pub code_block_overflow_x_scroll: bool,
5960
pub inline_code: TextStyleRefinement,
@@ -74,6 +75,7 @@ impl Default for MarkdownStyle {
7475
fn default() -> Self {
7576
Self {
7677
base_text_style: Default::default(),
78+
container_style: Default::default(),
7779
code_block: Default::default(),
7880
code_block_overflow_x_scroll: false,
7981
inline_code: Default::default(),
@@ -748,6 +750,12 @@ impl MarkdownElement {
748750
}
749751
}
750752

753+
impl Styled for MarkdownElement {
754+
fn style(&mut self) -> &mut StyleRefinement {
755+
&mut self.style.container_style
756+
}
757+
}
758+
751759
impl Element for MarkdownElement {
752760
type RequestLayoutState = RenderedMarkdown;
753761
type PrepaintState = Hitbox;
@@ -768,6 +776,7 @@ impl Element for MarkdownElement {
768776
cx: &mut App,
769777
) -> (gpui::LayoutId, Self::RequestLayoutState) {
770778
let mut builder = MarkdownElementBuilder::new(
779+
&self.style.container_style,
771780
self.style.base_text_style.clone(),
772781
self.style.syntax.clone(),
773782
);
@@ -1441,9 +1450,17 @@ struct ListStackEntry {
14411450
}
14421451

14431452
impl MarkdownElementBuilder {
1444-
fn new(base_text_style: TextStyle, syntax_theme: Arc<SyntaxTheme>) -> Self {
1453+
fn new(
1454+
container_style: &StyleRefinement,
1455+
base_text_style: TextStyle,
1456+
syntax_theme: Arc<SyntaxTheme>,
1457+
) -> Self {
14451458
Self {
1446-
div_stack: vec![div().debug_selector(|| "inner".into()).into()],
1459+
div_stack: vec![{
1460+
let mut base_div = div();
1461+
base_div.style().refine(container_style);
1462+
base_div.debug_selector(|| "inner".into()).into()
1463+
}],
14471464
rendered_lines: Vec::new(),
14481465
pending_line: PendingLine::default(),
14491466
rendered_links: Vec::new(),

0 commit comments

Comments
 (0)