Upgrade Iced and render Markdown tables
This commit is contained in:
@@ -47,7 +47,7 @@ pub(super) struct ToolResultCheck {
|
||||
stage: ToolCheckStage,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ChatMessage {
|
||||
pub(super) id: i32,
|
||||
pub(super) user: bool,
|
||||
@@ -59,7 +59,7 @@ pub(crate) struct ChatMessage {
|
||||
pub(super) reasoning_complete: bool,
|
||||
pub(super) reasoning_open: bool,
|
||||
pub(super) content: String,
|
||||
pub(super) markdown: Vec<markdown::Item>,
|
||||
pub(super) markdown: markdown::Content,
|
||||
}
|
||||
|
||||
impl ChatMessage {
|
||||
@@ -80,7 +80,7 @@ impl ChatMessage {
|
||||
} else {
|
||||
visible
|
||||
};
|
||||
self.markdown = markdown::parse(content).collect();
|
||||
self.markdown = markdown::Content::parse(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ impl From<StoredMessage> for ChatMessage {
|
||||
reasoning_complete: message.reasoning_complete,
|
||||
reasoning_open: false,
|
||||
content: message.content,
|
||||
markdown: Vec::new(),
|
||||
markdown: iced::widget::markdown::Content::new(),
|
||||
};
|
||||
message.refresh_markdown();
|
||||
message
|
||||
@@ -1349,6 +1349,37 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assistant_markdown_keeps_llm_tables() {
|
||||
let mut message = ChatMessage {
|
||||
id: 1,
|
||||
user: false,
|
||||
tool: false,
|
||||
system: false,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
reasoning_open: false,
|
||||
content: "### Core / Setup\n\n| File | Lines |\n|---|---:|\n| `src/app.rs` | **1,750** |\n| `src/engine.rs` | 2,400 |\n\n### Summary\n\nDone."
|
||||
.to_owned(),
|
||||
markdown: iced::widget::markdown::Content::new(),
|
||||
};
|
||||
|
||||
message.refresh_markdown();
|
||||
|
||||
let table = message.markdown.items().iter().find_map(|item| {
|
||||
if let iced::widget::markdown::Item::Table { columns, rows } = item {
|
||||
Some((columns, rows))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
let (columns, rows) = table.expect("the completed Markdown table must remain renderable");
|
||||
assert_eq!(columns.len(), 2);
|
||||
assert_eq!(rows.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn last_compaction_selects_its_tail_without_hiding_history() {
|
||||
let message = |id: i32, compaction: bool, tail: Option<i32>| ChatMessage {
|
||||
@@ -1362,7 +1393,7 @@ mod tests {
|
||||
reasoning_complete: true,
|
||||
reasoning_open: false,
|
||||
content: format!("message {id}"),
|
||||
markdown: Vec::new(),
|
||||
markdown: iced::widget::markdown::Content::new(),
|
||||
};
|
||||
let history = vec![
|
||||
message(1, false, None),
|
||||
@@ -1394,7 +1425,7 @@ mod tests {
|
||||
reasoning_complete: true,
|
||||
reasoning_open: false,
|
||||
content: format!("message {id}"),
|
||||
markdown: Vec::new(),
|
||||
markdown: iced::widget::markdown::Content::new(),
|
||||
};
|
||||
let mut history = vec![
|
||||
message(1, true, false, false, false),
|
||||
|
||||
Reference in New Issue
Block a user