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: Ensure code block copy button stays in the right spot (#26074)

Marshall Bowers886d8c1cab48
diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs
index c160b647cb3..e8313ea9128 100644
--- a/crates/markdown/src/markdown.rs
+++ b/crates/markdown/src/markdown.rs
@@ -611,6 +611,9 @@ impl Element for MarkdownElement {
None
};
+ // This is a parent container that we can position the copy button inside.
+ builder.push_div(div().relative().w_full(), range, markdown_end);
+
let mut code_block = div()
.id(("code-block", range.start))
.rounded_lg()
@@ -750,6 +753,12 @@ impl Element for MarkdownElement {
MarkdownTagEnd::CodeBlock => {
builder.trim_trailing_newline();
+ builder.pop_div();
+ builder.pop_code_block();
+ if self.style.code_block.text.is_some() {
+ builder.pop_text_style();
+ }
+
if self.markdown.read(cx).options.copy_code_block_buttons {
builder.flush_text();
builder.modify_current_div(|el| {
@@ -792,11 +801,8 @@ impl Element for MarkdownElement {
});
}
+ // Pop the parent container.
builder.pop_div();
- builder.pop_code_block();
- if self.style.code_block.text.is_some() {
- builder.pop_text_style();
- }
}
MarkdownTagEnd::HtmlBlock => builder.pop_div(),
MarkdownTagEnd::List(_) => {