From c9df963142d317f41b4998550d2cdc7ef78c90f2 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 19 Jun 2023 12:00:45 +0200 Subject: [PATCH] Allow message splitting with multiple cursors --- crates/ai/src/assistant.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/ai/src/assistant.rs b/crates/ai/src/assistant.rs index 853f7262d3..d5c50146c3 100644 --- a/crates/ai/src/assistant.rs +++ b/crates/ai/src/assistant.rs @@ -8,7 +8,7 @@ use collections::{HashMap, HashSet}; use editor::{ display_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, ToDisplayPoint}, scroll::autoscroll::{Autoscroll, AutoscrollStrategy}, - Anchor, Editor, + Anchor, Editor, ToOffset, }; use fs::Fs; use futures::{io::BufReader, AsyncBufReadExt, AsyncReadExt, Stream, StreamExt}; @@ -1294,8 +1294,14 @@ impl AssistantEditor { fn split(&mut self, _: &Split, cx: &mut ViewContext) { self.assistant.update(cx, |assistant, cx| { - let range = self.editor.read(cx).selections.newest::(cx).range(); - assistant.split_message(range, cx); + let selections = self.editor.read(cx).selections.disjoint_anchors(); + for selection in selections.into_iter() { + let buffer = self.editor.read(cx).buffer().read(cx).snapshot(cx); + let range = selection + .map(|endpoint| endpoint.to_offset(&buffer)) + .range(); + assistant.split_message(range, cx); + } }); }