Fix missing selection range in Vim visual line mode in the assistant panel (#25133)

Closes #25132

Release Notes:

- Fixed issues with `assistant: insert into editor` and `editor: copy` not inserting/copying the correct text inside of the assistant panel when selected using line-wise selection in Vim mode

---------

Co-authored-by: Ben Kunkle <ben.kunkle@gmail.com>
This commit is contained in:
RieN 7z 2025-02-25 09:15:15 +08:00 committed by GitHub
parent 2ea332421c
commit 980e1b533f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1514,15 +1514,11 @@ impl ContextEditor {
(!text.is_empty()).then_some((text, true)) (!text.is_empty()).then_some((text, true))
} else { } else {
let anchor = context_editor.selections.newest_anchor(); let selection = context_editor.selections.newest_adjusted(cx);
let text = context_editor let buffer = context_editor.buffer().read(cx).snapshot(cx);
.buffer() let selected_text = buffer.text_for_range(selection.range()).collect::<String>();
.read(cx)
.read(cx)
.text_for_range(anchor.range())
.collect::<String>();
(!text.is_empty()).then_some((text, false)) (!selected_text.is_empty()).then_some((selected_text, false))
} }
}) })
} }
@ -1777,23 +1773,16 @@ impl ContextEditor {
&mut self, &mut self,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> (String, CopyMetadata, Vec<text::Selection<usize>>) { ) -> (String, CopyMetadata, Vec<text::Selection<usize>>) {
let (snapshot, selection, creases) = self.editor.update(cx, |editor, cx| { let (selection, creases) = self.editor.update(cx, |editor, cx| {
let mut selection = editor.selections.newest::<Point>(cx); let mut selection = editor.selections.newest_adjusted(cx);
let snapshot = editor.buffer().read(cx).snapshot(cx); let snapshot = editor.buffer().read(cx).snapshot(cx);
let is_entire_line = selection.is_empty() || editor.selections.line_mode; selection.goal = SelectionGoal::None;
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;
}
let selection_start = snapshot.point_to_offset(selection.start); let selection_start = snapshot.point_to_offset(selection.start);
( (
snapshot.clone(), selection.map(|point| snapshot.point_to_offset(point)),
selection.clone(),
editor.display_map.update(cx, |display_map, cx| { editor.display_map.update(cx, |display_map, cx| {
display_map display_map
.snapshot(cx) .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 context = self.context.read(cx);
let mut text = String::new(); let mut text = String::new();