Skip to content

Commit b01857b

Browse files
authored
Add a dot at the end of chat lines during model replies to make the responses look smoother. (#262)
* add dot at the end of chatline * delete pub of the State * move the arm back
1 parent 3deaa69 commit b01857b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/chat/chat_line.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,24 @@ impl ChatLineRef {
407407
inner.label(id!(avatar_label)).set_text(text);
408408
}
409409

410-
pub fn set_message_text(&mut self, cx: &mut Cx, text: &str) {
410+
pub fn set_message_text(&mut self, cx: &mut Cx, text: &str, is_streaming: bool) {
411411
let Some(mut inner) = self.borrow_mut() else {
412412
return;
413413
};
414414

415415
match inner.edition_state {
416+
416417
ChatLineState::Editable | ChatLineState::NotEditable => {
417-
inner.text_input(id!(input)).set_text(text.trim());
418-
inner.label(id!(plain_text_message)).set_text(text.trim());
419-
inner.markdown(id!(markdown_message)).set_text(text.trim());
418+
if is_streaming && !text.is_empty() {
419+
let output = format!("{}{}", text, "●");
420+
inner.text_input(id!(input)).set_text(&output.trim());
421+
inner.label(id!(plain_text_message)).set_text(&output.trim());
422+
inner.markdown(id!(markdown_message)).set_text(&output.trim());
423+
} else {
424+
inner.text_input(id!(input)).set_text(text.trim());
425+
inner.label(id!(plain_text_message)).set_text(text.trim());
426+
inner.markdown(id!(markdown_message)).set_text(text.trim());
427+
}
420428

421429
// We know only AI assistant messages could be empty, so it is never
422430
// displayed in user's chat lines.

src/chat/chat_panel.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ impl ChatPanel {
885885
chat_line_item.set_regenerate_button_visible(true);
886886
};
887887

888-
chat_line_item.set_message_text(cx, &chat_line_data.content);
889888
chat_line_item.set_message_id(chat_line_data.id);
890889

891890
// Disable actions for the last chat line when model is streaming
@@ -897,8 +896,10 @@ impl ChatPanel {
897896
}
898897
) && item_id == messages_count - 1
899898
{
899+
chat_line_item.set_message_text(cx, &chat_line_data.content, true);
900900
chat_line_item.set_actions_enabled(cx, false);
901901
} else {
902+
chat_line_item.set_message_text(cx, &chat_line_data.content, false);
902903
chat_line_item.set_actions_enabled(cx, true);
903904
}
904905

0 commit comments

Comments
 (0)