T23a: AI chat, messages
- messages: yours in a quiet bubble, the assistant's as prose beside its mark, system notes, errors; avatars, headers with model and time, footers - MessageList over gpui's bottom-aligned list: drawn near the view, held at the newest, counting arrivals while away; a way back down; day separators - streaming text and markdown reveal toward the text as it grows, with a caret; a blinking cursor before the first words - CodeBlock with language, copy, run, apply, download and folding; MarkdownRenderer::code lets messages draw fences with it - pictures, grids, files, voice notes, video over host frames, link previews - quotes, actions, an editor that takes focus, versions, regenerate, stop and continue - errors with retry, a rate limit counting down, feedback, thinking blocks - gallery: the AI Chat page with scripted states
This commit is contained in:
1 parent
03f6ceb583
commit
c0afce2507
21 files changed
+3376
-34
No files matched your search
@@ -17,6 +17,7 @@ use crate::{
|
||||
};
|
||||
|
||||
type OnLink = Rc<dyn Fn(&str, &mut Window, &mut App)>;
|
||||
type DrawCode = Rc<dyn Fn(ElementId, Option<SharedString>, SharedString) -> AnyElement>;
|
||||
|
||||
/// Markdown as a document: headings, prose with its styles and links, lists and tasks, quotes, code colored as code, tables, rules, math and footnotes. A press on a link opens it, or hands it to the host.
|
||||
#[derive(IntoElement)]
|
||||
@@ -26,6 +27,7 @@ pub struct MarkdownRenderer {
|
||||
on_link: Option<OnLink>,
|
||||
size: TextSize,
|
||||
sections: Option<Entity<Sections>>,
|
||||
code: Option<DrawCode>,
|
||||
}
|
||||
|
||||
impl MarkdownRenderer {
|
||||
@@ -36,6 +38,7 @@ impl MarkdownRenderer {
|
||||
on_link: None,
|
||||
size: TextSize::Base,
|
||||
sections: None,
|
||||
code: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +54,15 @@ impl MarkdownRenderer {
|
||||
self
|
||||
}
|
||||
|
||||
/// Draws code blocks with the owner's element, given an id, the language and the code.
|
||||
pub fn code(
|
||||
mut self,
|
||||
draw: impl Fn(ElementId, Option<SharedString>, SharedString) -> AnyElement + 'static,
|
||||
) -> Self {
|
||||
self.code = Some(Rc::new(draw));
|
||||
self
|
||||
}
|
||||
|
||||
/// Takes link presses instead of the browser.
|
||||
pub fn on_link(mut self, handler: impl Fn(&str, &mut Window, &mut App) + 'static) -> Self {
|
||||
self.on_link = Some(Rc::new(handler));
|
||||
@@ -65,6 +77,7 @@ struct Draw<'a> {
|
||||
next: std::cell::Cell<usize>,
|
||||
sections: &'a Option<Entity<Sections>>,
|
||||
headings: std::cell::Cell<usize>,
|
||||
code: &'a Option<DrawCode>,
|
||||
}
|
||||
|
||||
impl Draw<'_> {
|
||||
@@ -192,6 +205,13 @@ impl Draw<'_> {
|
||||
.children(self.nodes(inner, cx))
|
||||
.into_any_element(),
|
||||
Node::Code { language, text } => {
|
||||
if let Some(draw) = self.code {
|
||||
return draw(
|
||||
self.key("code"),
|
||||
language.clone().map(Into::into),
|
||||
text.clone().into(),
|
||||
);
|
||||
}
|
||||
let styles = code_colors(text, cx);
|
||||
div()
|
||||
.flex()
|
||||
@@ -406,6 +426,7 @@ impl RenderOnce for MarkdownRenderer {
|
||||
next: std::cell::Cell::new(0),
|
||||
sections: &self.sections,
|
||||
headings: std::cell::Cell::new(0),
|
||||
code: &self.code,
|
||||
};
|
||||
div()
|
||||
.flex()
|
||||
|
||||
Reference in new issue
Block a user