Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
markdown_preview: Fix block quote last child bottom padding (#40343)
Jason Leee406ac6db9d3
diff --git a/crates/markdown_preview/src/markdown_renderer.rs b/crates/markdown_preview/src/markdown_renderer.rsindex a873771e001..489ce532f00 100644--- a/crates/markdown_preview/src/markdown_renderer.rs+++ b/crates/markdown_preview/src/markdown_renderer.rs@@ -61,6 +61,7 @@ pub struct RenderContext {syntax_theme: Arc<SyntaxTheme>,indent: usize,checkbox_clicked_callback: Option<CheckboxClickedCallback>,+ is_last_child: bool,}impl RenderContext {@@ -94,6 +95,7 @@ impl RenderContext {code_block_background_color: theme.colors().surface_background,code_span_background_color: theme.colors().editor_document_highlight_read_background,checkbox_clicked_callback: None,+ is_last_child: false,}}@@ -135,12 +137,25 @@ impl RenderContext {/// We give padding between "This is a block quote."/// and "And this is the next paragraph."fn with_common_p(&self, element: Div) -> Div {- if self.indent > 0 {+ if self.indent > 0 && !self.is_last_child {element.pb(self.scaled_rems(0.75))} else {element}}++ /// The is used to indicate that the current element is the last child or not of its parent.+ ///+ /// Then we can avoid adding padding to the bottom of the last child.+ fn with_last_child<R>(&mut self, is_last: bool, render: R) -> AnyElement+ where+ R: FnOnce(&mut Self) -> AnyElement,+ {+ self.is_last_child = is_last;+ let element = render(self);+ self.is_last_child = false;+ element+ }}pub fn render_parsed_markdown(@@ -585,7 +600,12 @@ fn render_markdown_block_quote(let children: Vec<AnyElement> = parsed.children.iter()- .map(|child| render_markdown_block(child, cx))+ .enumerate()+ .map(|(ix, child)| {+ cx.with_last_child(ix + 1 == parsed.children.len(), |cx| {+ render_markdown_block(child, cx)+ })+ }).collect();cx.indent -= 1;