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:
parent
5f9c91d05a
commit
3aa313010f
1 changed files with 43 additions and 53 deletions
|
@ -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,51 +504,47 @@ 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 {
|
IconName::Check
|
||||||
IconName::Check
|
} else {
|
||||||
} else {
|
IconName::Copy
|
||||||
IconName::Copy
|
},
|
||||||
},
|
)
|
||||||
)
|
.icon_color(Color::Muted)
|
||||||
.icon_color(Color::Muted)
|
.shape(ui::IconButtonShape::Square)
|
||||||
.shape(ui::IconButtonShape::Square)
|
.tooltip(Tooltip::text("Copy Code"))
|
||||||
.tooltip(Tooltip::text("Copy Code"))
|
.on_click({
|
||||||
.on_click({
|
let active_thread = active_thread.clone();
|
||||||
let active_thread = active_thread.clone();
|
let parsed_markdown = parsed_markdown.clone();
|
||||||
let parsed_markdown = parsed_markdown.clone();
|
let code_block_range = metadata.content_range.clone();
|
||||||
let code_block_range = metadata.content_range.clone();
|
move |_event, _window, cx| {
|
||||||
move |_event, _window, cx| {
|
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();
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.ok();
|
|
||||||
})
|
})
|
||||||
.detach();
|
.ok();
|
||||||
});
|
})
|
||||||
}
|
.detach();
|
||||||
}),
|
});
|
||||||
),
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.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.,
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue