diff --git a/crates/assistant_context_editor/src/context_editor.rs b/crates/assistant_context_editor/src/context_editor.rs index 578d4636c9..12a522f56a 100644 --- a/crates/assistant_context_editor/src/context_editor.rs +++ b/crates/assistant_context_editor/src/context_editor.rs @@ -1514,15 +1514,11 @@ impl ContextEditor { (!text.is_empty()).then_some((text, true)) } else { - let anchor = context_editor.selections.newest_anchor(); - let text = context_editor - .buffer() - .read(cx) - .read(cx) - .text_for_range(anchor.range()) - .collect::(); + let selection = context_editor.selections.newest_adjusted(cx); + let buffer = context_editor.buffer().read(cx).snapshot(cx); + let selected_text = buffer.text_for_range(selection.range()).collect::(); - (!text.is_empty()).then_some((text, false)) + (!selected_text.is_empty()).then_some((selected_text, false)) } }) } @@ -1777,23 +1773,16 @@ impl ContextEditor { &mut self, cx: &mut Context, ) -> (String, CopyMetadata, Vec>) { - let (snapshot, selection, creases) = self.editor.update(cx, |editor, cx| { - let mut selection = editor.selections.newest::(cx); + let (selection, creases) = self.editor.update(cx, |editor, cx| { + let mut selection = editor.selections.newest_adjusted(cx); let snapshot = editor.buffer().read(cx).snapshot(cx); - let is_entire_line = selection.is_empty() || editor.selections.line_mode; - if is_entire_line { - selection.start = Point::new(selection.start.row, 0); - selection.end = - cmp::min(snapshot.max_point(), Point::new(selection.start.row + 1, 0)); - selection.goal = SelectionGoal::None; - } + selection.goal = SelectionGoal::None; let selection_start = snapshot.point_to_offset(selection.start); ( - snapshot.clone(), - selection.clone(), + selection.map(|point| snapshot.point_to_offset(point)), editor.display_map.update(cx, |display_map, cx| { display_map .snapshot(cx) @@ -1833,7 +1822,6 @@ impl ContextEditor { ) }); - let selection = selection.map(|point| snapshot.point_to_offset(point)); let context = self.context.read(cx); let mut text = String::new();