Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Make agent::addSelectionToThread use current line when no selection (#48045)
Peter Trippf22f4db6c079
diff --git a/crates/agent_ui/src/completion_provider.rs b/crates/agent_ui/src/completion_provider.rsindex b858db698cf..baa57368e50 100644--- a/crates/agent_ui/src/completion_provider.rs+++ b/crates/agent_ui/src/completion_provider.rs@@ -2050,7 +2050,17 @@ fn selection_ranges(selections.into_iter()- .map(|s| snapshot.anchor_after(s.start)..snapshot.anchor_before(s.end))+ .map(|s| {+ let (start, end) = if s.is_empty() {+ let row = multi_buffer::MultiBufferRow(s.start.row);+ let line_start = text::Point::new(s.start.row, 0);+ let line_end = text::Point::new(s.start.row, snapshot.line_len(row));+ (line_start, line_end)+ } else {+ (s.start, s.end)+ };+ snapshot.anchor_after(start)..snapshot.anchor_before(end)+ }).flat_map(|range| {let (start_buffer, start) = buffer.text_anchor_for_position(range.start, cx)?;let (end_buffer, end) = buffer.text_anchor_for_position(range.end, cx)?;diff --git a/crates/agent_ui/src/text_thread_editor.rs b/crates/agent_ui/src/text_thread_editor.rsindex 1780e03b9fb..b878be82e38 100644--- a/crates/agent_ui/src/text_thread_editor.rs+++ b/crates/agent_ui/src/text_thread_editor.rs@@ -1509,9 +1509,16 @@ impl TextThreadEditor {.selections.all_adjusted(&editor.display_snapshot(cx)).into_iter()- .filter_map(|s| {- (!s.is_empty())- .then(|| snapshot.anchor_after(s.start)..snapshot.anchor_before(s.end))+ .map(|s| {+ let (start, end) = if s.is_empty() {+ let row = multi_buffer::MultiBufferRow(s.start.row);+ let line_start = text::Point::new(s.start.row, 0);+ let line_end = text::Point::new(s.start.row, snapshot.line_len(row));+ (line_start, line_end)+ } else {+ (s.start, s.end)+ };+ snapshot.anchor_after(start)..snapshot.anchor_before(end)}).collect::<Vec<_>>()});