mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-27 00:41:37 +00:00
Show message headers again
Co-Authored-By: Julia Risley <julia@zed.dev>
This commit is contained in:
parent
2842fc2b1d
commit
00cede63a8
1 changed files with 108 additions and 10 deletions
|
@ -6,7 +6,7 @@ use anyhow::{anyhow, Result};
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
use editor::{
|
use editor::{
|
||||||
display_map::ToDisplayPoint,
|
display_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, ToDisplayPoint},
|
||||||
scroll::{
|
scroll::{
|
||||||
autoscroll::{Autoscroll, AutoscrollStrategy},
|
autoscroll::{Autoscroll, AutoscrollStrategy},
|
||||||
ScrollAnchor,
|
ScrollAnchor,
|
||||||
|
@ -818,6 +818,7 @@ enum AssistantEditorEvent {
|
||||||
struct AssistantEditor {
|
struct AssistantEditor {
|
||||||
assistant: ModelHandle<Assistant>,
|
assistant: ModelHandle<Assistant>,
|
||||||
editor: ViewHandle<Editor>,
|
editor: ViewHandle<Editor>,
|
||||||
|
blocks: HashSet<BlockId>,
|
||||||
scroll_bottom: ScrollAnchor,
|
scroll_bottom: ScrollAnchor,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
@ -845,6 +846,7 @@ impl AssistantEditor {
|
||||||
Self {
|
Self {
|
||||||
assistant,
|
assistant,
|
||||||
editor,
|
editor,
|
||||||
|
blocks: Default::default(),
|
||||||
scroll_bottom: ScrollAnchor {
|
scroll_bottom: ScrollAnchor {
|
||||||
offset: Default::default(),
|
offset: Default::default(),
|
||||||
anchor: Anchor::max(),
|
anchor: Anchor::max(),
|
||||||
|
@ -905,19 +907,115 @@ impl AssistantEditor {
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
AssistantEvent::MessagesEdited => {
|
AssistantEvent::MessagesEdited => {
|
||||||
let selections = self.editor.read(cx).selections.all::<usize>(cx);
|
self.editor.update(cx, |editor, cx| {
|
||||||
let selection_heads = selections
|
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||||
.iter()
|
let excerpt_id = *buffer.as_singleton().unwrap().0;
|
||||||
.map(|selection| selection.head())
|
let old_blocks = std::mem::take(&mut self.blocks);
|
||||||
.collect::<HashSet<usize>>();
|
let new_blocks =
|
||||||
// let ids = ids.iter().copied().collect::<HashSet<_>>();
|
self.assistant
|
||||||
// self.assistant.update(cx, |assistant, cx| {
|
.read(cx)
|
||||||
// assistant.remove_empty_messages(ids, selection_heads, cx)
|
.messages(cx)
|
||||||
// });
|
.map(|(message, metadata, _)| BlockProperties {
|
||||||
|
position: buffer.anchor_in_excerpt(excerpt_id, message.start),
|
||||||
|
height: 2,
|
||||||
|
style: BlockStyle::Sticky,
|
||||||
|
render: Arc::new({
|
||||||
|
let assistant = self.assistant.clone();
|
||||||
|
let metadata = metadata.clone();
|
||||||
|
let message = message.clone();
|
||||||
|
move |cx| {
|
||||||
|
enum Sender {}
|
||||||
|
enum ErrorTooltip {}
|
||||||
|
|
||||||
|
let theme = theme::current(cx);
|
||||||
|
let style = &theme.assistant;
|
||||||
|
let message_id = message.id;
|
||||||
|
let sender = MouseEventHandler::<Sender, _>::new(
|
||||||
|
message_id.0,
|
||||||
|
cx,
|
||||||
|
|state, _| match metadata.role {
|
||||||
|
Role::User => {
|
||||||
|
let style =
|
||||||
|
style.user_sender.style_for(state, false);
|
||||||
|
Label::new("You", style.text.clone())
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
}
|
||||||
|
Role::Assistant => {
|
||||||
|
let style = style
|
||||||
|
.assistant_sender
|
||||||
|
.style_for(state, false);
|
||||||
|
Label::new("Assistant", style.text.clone())
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
}
|
||||||
|
Role::System => {
|
||||||
|
let style =
|
||||||
|
style.system_sender.style_for(state, false);
|
||||||
|
Label::new("System", style.text.clone())
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
.on_down(MouseButton::Left, {
|
||||||
|
let assistant = assistant.clone();
|
||||||
|
move |_, _, cx| {
|
||||||
|
assistant.update(cx, |assistant, cx| {
|
||||||
|
assistant.cycle_message_role(message_id, cx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Flex::row()
|
||||||
|
.with_child(sender.aligned())
|
||||||
|
.with_child(
|
||||||
|
Label::new(
|
||||||
|
metadata.sent_at.format("%I:%M%P").to_string(),
|
||||||
|
style.sent_at.text.clone(),
|
||||||
|
)
|
||||||
|
.contained()
|
||||||
|
.with_style(style.sent_at.container)
|
||||||
|
.aligned(),
|
||||||
|
)
|
||||||
|
.with_children(metadata.error.clone().map(|error| {
|
||||||
|
Svg::new("icons/circle_x_mark_12.svg")
|
||||||
|
.with_color(style.error_icon.color)
|
||||||
|
.constrained()
|
||||||
|
.with_width(style.error_icon.width)
|
||||||
|
.contained()
|
||||||
|
.with_style(style.error_icon.container)
|
||||||
|
.with_tooltip::<ErrorTooltip>(
|
||||||
|
message_id.0,
|
||||||
|
error,
|
||||||
|
None,
|
||||||
|
theme.tooltip.clone(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.aligned()
|
||||||
|
}))
|
||||||
|
.aligned()
|
||||||
|
.left()
|
||||||
|
.contained()
|
||||||
|
.with_style(style.header)
|
||||||
|
.into_any()
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
disposition: BlockDisposition::Above,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
editor.remove_blocks(old_blocks, cx);
|
||||||
|
let ids = editor.insert_blocks(new_blocks, cx);
|
||||||
|
self.blocks = HashSet::from_iter(ids);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AssistantEvent::SummaryChanged => {
|
AssistantEvent::SummaryChanged => {
|
||||||
cx.emit(AssistantEditorEvent::TabContentChanged);
|
cx.emit(AssistantEditorEvent::TabContentChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
AssistantEvent::StreamedCompletion => {
|
AssistantEvent::StreamedCompletion => {
|
||||||
self.editor.update(cx, |editor, cx| {
|
self.editor.update(cx, |editor, cx| {
|
||||||
let snapshot = editor.snapshot(cx);
|
let snapshot = editor.snapshot(cx);
|
||||||
|
|
Loading…
Reference in a new issue