agent: Make markdown code blocks uncollapsed by default (#29424)

Seeing the markdown code stream in is actually more helpful than hiding
parts of it; parts that you may be interested in.

Release Notes:

- N/A
This commit is contained in:
Danilo Leal 2025-04-25 14:39:51 -03:00 committed by GitHub
parent 5f9c91d05a
commit 3aa313010f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -483,7 +483,7 @@ fn render_markdown_code_block(
.expanded_code_blocks .expanded_code_blocks
.get(&(message_id, ix)) .get(&(message_id, ix))
.copied() .copied()
.unwrap_or(false); .unwrap_or(true);
let codeblock_header_bg = cx let codeblock_header_bg = cx
.theme() .theme()
@ -504,9 +504,9 @@ fn render_markdown_code_block(
.children(label) .children(label)
.child( .child(
h_flex() h_flex()
.visible_on_hover("codeblock_container")
.gap_1() .gap_1()
.child( .child(
div().visible_on_hover("codeblock_container").child(
IconButton::new( IconButton::new(
("copy-markdown-code", ix), ("copy-markdown-code", ix),
if codeblock_was_copied { if codeblock_was_copied {
@ -526,19 +526,16 @@ fn render_markdown_code_block(
active_thread.update(cx, |this, cx| { active_thread.update(cx, |this, cx| {
this.copied_code_block_ids.insert((message_id, ix)); this.copied_code_block_ids.insert((message_id, ix));
let code = parsed_markdown.source()[code_block_range.clone()] let code =
.to_string(); parsed_markdown.source()[code_block_range.clone()].to_string();
cx.write_to_clipboard(ClipboardItem::new_string(code)); cx.write_to_clipboard(ClipboardItem::new_string(code));
cx.spawn(async move |this, cx| { cx.spawn(async move |this, cx| {
cx.background_executor() cx.background_executor().timer(Duration::from_secs(2)).await;
.timer(Duration::from_secs(2))
.await;
cx.update(|cx| { cx.update(|cx| {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.copied_code_block_ids this.copied_code_block_ids.remove(&(message_id, ix));
.remove(&(message_id, ix));
cx.notify(); cx.notify();
}) })
}) })
@ -548,7 +545,6 @@ fn render_markdown_code_block(
}); });
} }
}), }),
),
) )
.when( .when(
metadata.line_count > MAX_UNCOLLAPSED_LINES_IN_CODE_BLOCK, metadata.line_count > MAX_UNCOLLAPSED_LINES_IN_CODE_BLOCK,
@ -576,7 +572,7 @@ fn render_markdown_code_block(
let is_expanded = this let is_expanded = this
.expanded_code_blocks .expanded_code_blocks
.entry((message_id, ix)) .entry((message_id, ix))
.or_insert(false); .or_insert(true);
*is_expanded = !*is_expanded; *is_expanded = !*is_expanded;
cx.notify(); cx.notify();
}); });
@ -2113,13 +2109,15 @@ impl ActiveThread {
}), }),
transform: Some(Arc::new({ transform: Some(Arc::new({
let active_thread = cx.entity(); let active_thread = cx.entity();
let editor_bg = cx.theme().colors().editor_background;
move |el, range, metadata, _, cx| { move |el, range, metadata, _, cx| {
let is_expanded = active_thread let is_expanded = active_thread
.read(cx) .read(cx)
.expanded_code_blocks .expanded_code_blocks
.get(&(message_id, range.start)) .get(&(message_id, range.start))
.copied() .copied()
.unwrap_or(false); .unwrap_or(true);
if is_expanded if is_expanded
|| metadata.line_count || metadata.line_count
@ -2135,19 +2133,11 @@ impl ActiveThread {
.w_full() .w_full()
.h_1_4() .h_1_4()
.rounded_b_lg() .rounded_b_lg()
.bg(gpui::linear_gradient( .bg(linear_gradient(
0., 0.,
gpui::linear_color_stop( linear_color_stop(editor_bg, 0.),
cx.theme() linear_color_stop(
.colors() editor_bg.opacity(0.),
.editor_background,
0.,
),
gpui::linear_color_stop(
cx.theme()
.colors()
.editor_background
.opacity(0.),
1., 1.,
), ),
)), )),