diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 92e3f215c8..b6bd583587 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -1685,9 +1685,11 @@ impl ContextEditor { return; }; + let selection = editor.update(cx, |editor, cx| editor.selections.newest_adjusted(cx)); let editor = editor.read(cx); - let range = editor.selections.newest::(cx).range(); let buffer = editor.buffer().read(cx).snapshot(cx); + let range = editor::ToOffset::to_offset(&selection.start, &buffer) + ..editor::ToOffset::to_offset(&selection.end, &buffer); let start_language = buffer.language_at(range.start); let end_language = buffer.language_at(range.end); let language_name = if start_language == end_language { diff --git a/crates/editor/src/selections_collection.rs b/crates/editor/src/selections_collection.rs index 3c2c428377..4161792af5 100644 --- a/crates/editor/src/selections_collection.rs +++ b/crates/editor/src/selections_collection.rs @@ -157,6 +157,18 @@ impl SelectionsCollection { selections } + /// Returns the newest selection, adjusted to take into account the selection line_mode + pub fn newest_adjusted(&self, cx: &mut AppContext) -> Selection { + let mut selection = self.newest::(cx); + if self.line_mode { + let map = self.display_map(cx); + let new_range = map.expand_to_line(selection.range()); + selection.start = new_range.start; + selection.end = new_range.end; + } + selection + } + pub fn all_adjusted_display( &self, cx: &mut AppContext,