Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Make markdown code blocks uncollapsed by default (#29424)
Danilo Leal3aa313010fd9
diff --git a/crates/agent/src/active_thread.rs b/crates/agent/src/active_thread.rsindex 0d0e2dd08db..f93af157c18 100644--- a/crates/agent/src/active_thread.rs+++ b/crates/agent/src/active_thread.rs@@ -483,7 +483,7 @@ fn render_markdown_code_block(.expanded_code_blocks.get(&(message_id, ix)).copied()- .unwrap_or(false);+ .unwrap_or(true);let codeblock_header_bg = cx.theme()@@ -504,51 +504,47 @@ fn render_markdown_code_block(.children(label).child(h_flex()+ .visible_on_hover("codeblock_container").gap_1().child(- div().visible_on_hover("codeblock_container").child(- IconButton::new(- ("copy-markdown-code", ix),- if codeblock_was_copied {- IconName::Check- } else {- IconName::Copy- },- )- .icon_color(Color::Muted)- .shape(ui::IconButtonShape::Square)- .tooltip(Tooltip::text("Copy Code"))- .on_click({- let active_thread = active_thread.clone();- let parsed_markdown = parsed_markdown.clone();- let code_block_range = metadata.content_range.clone();- move |_event, _window, cx| {- active_thread.update(cx, |this, cx| {- this.copied_code_block_ids.insert((message_id, ix));-- let code = parsed_markdown.source()[code_block_range.clone()]- .to_string();- cx.write_to_clipboard(ClipboardItem::new_string(code));-- cx.spawn(async move |this, cx| {- cx.background_executor()- .timer(Duration::from_secs(2))- .await;-- cx.update(|cx| {- this.update(cx, |this, cx| {- this.copied_code_block_ids- .remove(&(message_id, ix));- cx.notify();- })+ IconButton::new(+ ("copy-markdown-code", ix),+ if codeblock_was_copied {+ IconName::Check+ } else {+ IconName::Copy+ },+ )+ .icon_color(Color::Muted)+ .shape(ui::IconButtonShape::Square)+ .tooltip(Tooltip::text("Copy Code"))+ .on_click({+ let active_thread = active_thread.clone();+ let parsed_markdown = parsed_markdown.clone();+ let code_block_range = metadata.content_range.clone();+ move |_event, _window, cx| {+ active_thread.update(cx, |this, cx| {+ this.copied_code_block_ids.insert((message_id, ix));++ let code =+ parsed_markdown.source()[code_block_range.clone()].to_string();+ cx.write_to_clipboard(ClipboardItem::new_string(code));++ cx.spawn(async move |this, cx| {+ cx.background_executor().timer(Duration::from_secs(2)).await;++ cx.update(|cx| {+ this.update(cx, |this, cx| {+ this.copied_code_block_ids.remove(&(message_id, ix));+ cx.notify();})- .ok();})- .detach();- });- }- }),- ),+ .ok();+ })+ .detach();+ });+ }+ }),).when(metadata.line_count > MAX_UNCOLLAPSED_LINES_IN_CODE_BLOCK,@@ -576,7 +572,7 @@ fn render_markdown_code_block(let is_expanded = this.expanded_code_blocks.entry((message_id, ix))- .or_insert(false);+ .or_insert(true);*is_expanded = !*is_expanded;cx.notify();});@@ -2113,13 +2109,15 @@ impl ActiveThread {}),transform: Some(Arc::new({let active_thread = cx.entity();+ let editor_bg = cx.theme().colors().editor_background;+move |el, range, metadata, _, cx| {let is_expanded = active_thread.read(cx).expanded_code_blocks.get(&(message_id, range.start)).copied()- .unwrap_or(false);+ .unwrap_or(true);if is_expanded|| metadata.line_count@@ -2135,19 +2133,11 @@ impl ActiveThread {.w_full().h_1_4().rounded_b_lg()- .bg(gpui::linear_gradient(+ .bg(linear_gradient(0.,- gpui::linear_color_stop(- cx.theme()- .colors()- .editor_background,- 0.,- ),- gpui::linear_color_stop(- cx.theme()- .colors()- .editor_background- .opacity(0.),+ linear_color_stop(editor_bg, 0.),+ linear_color_stop(+ editor_bg.opacity(0.),1.,),)),