agent_ui: Fix show markdown list checked state (#43567)

Closes #37527

This PR adds support for showing the list state of a list item inside
the agent UI.

**Before**
<img width="643" height="505" alt="Screenshot 2025-11-26 at 16 21 31"
src="https://github.com/user-attachments/assets/30c78022-4096-4fe4-a6cc-db208d03900f"
/>

**After**
<img width="640" height="503" alt="Screenshot 2025-11-26 at 16 41 32"
src="https://github.com/user-attachments/assets/ece14172-79a5-4d5e-a577-4b87db04280f"
/>

Release Notes:
- Agent UI now show the checked state of a list item

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
Remco Smits
2025-12-08 14:04:49 +00:00
committed by GitHub
co-authored by Danilo Leal
parent e6214b2b71
commit 2260b87ea8
2 changed files with 65 additions and 26 deletions
+25 -5
View File
@@ -7,6 +7,7 @@ use gpui::HitboxBehavior;
use language::LanguageName;
use log::Level;
pub use path_range::{LineCol, PathWithRange};
use ui::Checkbox;
use std::borrow::Cow;
use std::iter;
@@ -795,7 +796,7 @@ impl Element for MarkdownElement {
let mut code_block_ids = HashSet::default();
let mut current_img_block_range: Option<Range<usize>> = None;
for (range, event) in parsed_markdown.events.iter() {
for (index, (range, event)) in parsed_markdown.events.iter().enumerate() {
// Skip alt text for images that rendered
if let Some(current_img_block_range) = &current_img_block_range
&& current_img_block_range.end > range.end
@@ -945,13 +946,29 @@ impl Element for MarkdownElement {
MarkdownTag::HtmlBlock => builder.push_div(div(), range, markdown_end),
MarkdownTag::List(bullet_index) => {
builder.push_list(*bullet_index);
builder.push_div(div().pl_4(), range, markdown_end);
builder.push_div(div().pl_2p5(), range, markdown_end);
}
MarkdownTag::Item => {
let bullet = if let Some(bullet_index) = builder.next_bullet_index() {
format!("{}.", bullet_index)
let bullet = if let Some((_, MarkdownEvent::TaskListMarker(checked))) =
parsed_markdown.events.get(index.saturating_add(1))
{
let source = &parsed_markdown.source()[range.clone()];
Checkbox::new(
ElementId::Name(source.to_string().into()),
if *checked {
ToggleState::Selected
} else {
ToggleState::Unselected
},
)
.fill()
.visualization_only(true)
.into_any_element()
} else if let Some(bullet_index) = builder.next_bullet_index() {
div().child(format!("{}.", bullet_index)).into_any_element()
} else {
"•".to_string()
div().child("•").into_any_element()
};
builder.push_div(
div()
@@ -1226,6 +1243,9 @@ impl Element for MarkdownElement {
}
MarkdownEvent::SoftBreak => builder.push_text(" ", range.clone()),
MarkdownEvent::HardBreak => builder.push_text("\n", range.clone()),
MarkdownEvent::TaskListMarker(_) => {
// handled inside the `MarkdownTag::Item` case
}
_ => log::debug!("unsupported markdown event {:?}", event),
}
}