Re-enable copy support in the assistant

This commit is contained in:
Antonio Scandurra 2023-06-14 09:40:43 +02:00
parent 27c83ca3f7
commit 7dab17e233

View file

@ -1131,25 +1131,19 @@ impl AssistantEditor {
let mut offset = 0; let mut offset = 0;
let mut copied_text = String::new(); let mut copied_text = String::new();
let mut spanned_messages = 0; let mut spanned_messages = 0;
for message in &assistant.messages { for (message, metadata, message_range) in assistant.messages(cx) {
todo!();
// let message_range = offset..offset + message.content.read(cx).len() + 1;
let message_range = offset..offset + 1;
if message_range.start >= selection.range().end { if message_range.start >= selection.range().end {
break; break;
} else if message_range.end >= selection.range().start { } else if message_range.end >= selection.range().start {
let range = cmp::max(message_range.start, selection.range().start) let range = cmp::max(message_range.start, selection.range().start)
..cmp::min(message_range.end, selection.range().end); ..cmp::min(message_range.end, selection.range().end);
if !range.is_empty() { if !range.is_empty() {
if let Some(metadata) = assistant.messages_metadata.get(&message.id) { spanned_messages += 1;
spanned_messages += 1; write!(&mut copied_text, "## {}\n\n", metadata.role).unwrap();
write!(&mut copied_text, "## {}\n\n", metadata.role).unwrap(); for chunk in assistant.buffer.read(cx).text_for_range(range) {
for chunk in assistant.buffer.read(cx).text_for_range(range) { copied_text.push_str(&chunk);
copied_text.push_str(&chunk);
}
copied_text.push('\n');
} }
copied_text.push('\n');
} }
} }