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
.get(&(message_id, ix))
.copied()
.unwrap_or(false);
.unwrap_or(true);
let codeblock_header_bg = cx
.theme()
@ -504,9 +504,9 @@ 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 {
@ -526,19 +526,16 @@ fn render_markdown_code_block(
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();
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.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));
this.copied_code_block_ids.remove(&(message_id, ix));
cx.notify();
})
})
@ -548,7 +545,6 @@ fn render_markdown_code_block(
});
}
}),
),
)
.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.,
),
)),