Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/agent_ui/src/acp/completion_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,9 @@ impl ContextPickerCompletionProvider {
.active_item(cx)
.and_then(|item| item.downcast::<Editor>())
.is_some_and(|editor| {
editor.update(cx, |editor, cx| editor.has_non_empty_selection(cx))
editor.update(cx, |editor, cx| {
editor.has_non_empty_selection(&editor.display_snapshot(cx))
})
});
if has_selection {
entries.push(ContextPickerEntry::Action(
Expand Down
41 changes: 31 additions & 10 deletions crates/agent_ui/src/agent_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ fn update_editor_selection(
window: &mut Window,
cx: &mut Context<Editor>,
) {
let newest_cursor = editor.selections.newest::<Point>(cx).head();
let newest_cursor = editor
.selections
.newest::<Point>(&editor.display_snapshot(cx))
.head();

if !diff_hunks.iter().any(|hunk| {
hunk.row_range
Expand Down Expand Up @@ -1895,7 +1898,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(1, 0)..Point::new(1, 0)
);
Expand All @@ -1909,7 +1914,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
Expand All @@ -1930,7 +1937,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
Expand Down Expand Up @@ -1962,7 +1971,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
Expand Down Expand Up @@ -2119,7 +2130,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(1, 0)..Point::new(1, 0)
);
Expand Down Expand Up @@ -2160,7 +2173,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
Expand All @@ -2181,7 +2196,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
Expand All @@ -2207,7 +2224,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
Expand Down Expand Up @@ -2240,7 +2259,9 @@ mod tests {
);
assert_eq!(
editor2
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(0, 0)..Point::new(0, 0)
);
Expand Down
8 changes: 6 additions & 2 deletions crates/agent_ui/src/context_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,11 @@ pub(crate) fn available_context_picker_entries(
.read(cx)
.active_item(cx)
.and_then(|item| item.downcast::<Editor>())
.is_some_and(|editor| editor.update(cx, |editor, cx| editor.has_non_empty_selection(cx)));
.is_some_and(|editor| {
editor.update(cx, |editor, cx| {
editor.has_non_empty_selection(&editor.display_snapshot(cx))
})
});
if has_selection {
entries.push(ContextPickerEntry::Action(
ContextPickerAction::AddSelections,
Expand Down Expand Up @@ -754,7 +758,7 @@ pub(crate) fn selection_ranges(
};

editor.update(cx, |editor, cx| {
let selections = editor.selections.all_adjusted(cx);
let selections = editor.selections.all_adjusted(&editor.display_snapshot(cx));

let buffer = editor.buffer().clone().read(cx);
let snapshot = buffer.snapshot(cx);
Expand Down
17 changes: 12 additions & 5 deletions crates/agent_ui/src/inline_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,12 @@ impl InlineAssistant {
cx: &mut App,
) {
let (snapshot, initial_selections, newest_selection) = editor.update(cx, |editor, cx| {
let selections = editor.selections.all::<Point>(cx);
let newest_selection = editor.selections.newest::<Point>(cx);
(editor.snapshot(window, cx), selections, newest_selection)
let snapshot = editor.snapshot(window, cx);
let selections = editor.selections.all::<Point>(&snapshot.display_snapshot);
let newest_selection = editor
.selections
.newest::<Point>(&snapshot.display_snapshot);
(snapshot, selections, newest_selection)
});

// Check if there is already an inline assistant that contains the
Expand Down Expand Up @@ -808,7 +811,9 @@ impl InlineAssistant {
if editor.read(cx).selections.count() == 1 {
let (selection, buffer) = editor.update(cx, |editor, cx| {
(
editor.selections.newest::<usize>(cx),
editor
.selections
.newest::<usize>(&editor.display_snapshot(cx)),
editor.buffer().read(cx).snapshot(cx),
)
});
Expand Down Expand Up @@ -839,7 +844,9 @@ impl InlineAssistant {
if editor.read(cx).selections.count() == 1 {
let (selection, buffer) = editor.update(cx, |editor, cx| {
(
editor.selections.newest::<usize>(cx),
editor
.selections
.newest::<usize>(&editor.display_snapshot(cx)),
editor.buffer().read(cx).snapshot(cx),
)
});
Expand Down
45 changes: 32 additions & 13 deletions crates/agent_ui/src/text_thread_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ impl TextThreadEditor {
}

fn cursors(&self, cx: &mut App) -> Vec<usize> {
let selections = self
.editor
.update(cx, |editor, cx| editor.selections.all::<usize>(cx));
let selections = self.editor.update(cx, |editor, cx| {
editor.selections.all::<usize>(&editor.display_snapshot(cx))
});
selections
.into_iter()
.map(|selection| selection.head())
Expand All @@ -446,7 +446,10 @@ impl TextThreadEditor {
editor.transact(window, cx, |editor, window, cx| {
editor.change_selections(Default::default(), window, cx, |s| s.try_cancel());
let snapshot = editor.buffer().read(cx).snapshot(cx);
let newest_cursor = editor.selections.newest::<Point>(cx).head();
let newest_cursor = editor
.selections
.newest::<Point>(&editor.display_snapshot(cx))
.head();
if newest_cursor.column > 0
|| snapshot
.chars_at(newest_cursor)
Expand Down Expand Up @@ -1265,11 +1268,19 @@ impl TextThreadEditor {

let context_editor = context_editor_view.read(cx).editor.clone();
context_editor.update(cx, |context_editor, cx| {
if context_editor.selections.newest::<Point>(cx).is_empty() {
let display_map = context_editor.display_snapshot(cx);
if context_editor
.selections
.newest::<Point>(&display_map)
.is_empty()
{
let snapshot = context_editor.buffer().read(cx).snapshot(cx);
let (_, _, snapshot) = snapshot.as_singleton()?;

let head = context_editor.selections.newest::<Point>(cx).head();
let head = context_editor
.selections
.newest::<Point>(&display_map)
.head();
let offset = snapshot.point_to_offset(head);

let surrounding_code_block_range = find_surrounding_code_block(snapshot, offset)?;
Expand All @@ -1286,7 +1297,7 @@ impl TextThreadEditor {

(!text.is_empty()).then_some((text, true))
} else {
let selection = context_editor.selections.newest_adjusted(cx);
let selection = context_editor.selections.newest_adjusted(&display_map);
let buffer = context_editor.buffer().read(cx).snapshot(cx);
let selected_text = buffer.text_for_range(selection.range()).collect::<String>();

Expand Down Expand Up @@ -1474,7 +1485,7 @@ impl TextThreadEditor {
let selections = editor.update(cx, |editor, cx| {
editor
.selections
.all_adjusted(cx)
.all_adjusted(&editor.display_snapshot(cx))
.into_iter()
.filter_map(|s| {
(!s.is_empty())
Expand Down Expand Up @@ -1506,7 +1517,10 @@ impl TextThreadEditor {
self.editor.update(cx, |editor, cx| {
editor.insert("\n", window, cx);
for (text, crease_title) in creases {
let point = editor.selections.newest::<Point>(cx).head();
let point = editor
.selections
.newest::<Point>(&editor.display_snapshot(cx))
.head();
let start_row = MultiBufferRow(point.row);

editor.insert(&text, window, cx);
Expand Down Expand Up @@ -1578,7 +1592,9 @@ impl TextThreadEditor {
cx: &mut Context<Self>,
) -> (String, CopyMetadata, Vec<text::Selection<usize>>) {
let (mut selection, creases) = self.editor.update(cx, |editor, cx| {
let mut selection = editor.selections.newest_adjusted(cx);
let mut selection = editor
.selections
.newest_adjusted(&editor.display_snapshot(cx));
let snapshot = editor.buffer().read(cx).snapshot(cx);

selection.goal = SelectionGoal::None;
Expand Down Expand Up @@ -1697,7 +1713,10 @@ impl TextThreadEditor {

if images.is_empty() {
self.editor.update(cx, |editor, cx| {
let paste_position = editor.selections.newest::<usize>(cx).head();
let paste_position = editor
.selections
.newest::<usize>(&editor.display_snapshot(cx))
.head();
editor.paste(action, window, cx);

if let Some(metadata) = metadata {
Expand Down Expand Up @@ -1744,13 +1763,13 @@ impl TextThreadEditor {
editor.transact(window, cx, |editor, _window, cx| {
let edits = editor
.selections
.all::<usize>(cx)
.all::<usize>(&editor.display_snapshot(cx))
.into_iter()
.map(|selection| (selection.start..selection.end, "\n"));
editor.edit(edits, cx);

let snapshot = editor.buffer().read(cx).snapshot(cx);
for selection in editor.selections.all::<usize>(cx) {
for selection in editor.selections.all::<usize>(&editor.display_snapshot(cx)) {
image_positions.push(snapshot.anchor_before(selection.end));
}
});
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant_slash_commands/src/selection_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl SlashCommand for SelectionCommand {
editor.update(cx, |editor, cx| {
let selection_ranges = editor
.selections
.all_adjusted(cx)
.all_adjusted(&editor.display_snapshot(cx))
.iter()
.map(|selection| selection.range())
.collect::<Vec<_>>();
Expand Down
4 changes: 2 additions & 2 deletions crates/collab/src/tests/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T
6..9
);
rename.editor.update(cx, |rename_editor, cx| {
let rename_selection = rename_editor.selections.newest::<usize>(cx);
let rename_selection = rename_editor.selections.newest::<usize>(&rename_editor.display_snapshot(cx));
assert_eq!(
rename_selection.range(),
0..3,
Expand Down Expand Up @@ -924,7 +924,7 @@ async fn test_collaborating_with_renames(cx_a: &mut TestAppContext, cx_b: &mut T
let lsp_rename_end = rename.range.end.to_offset(&buffer);
assert_eq!(lsp_rename_start..lsp_rename_end, 6..9);
rename.editor.update(cx, |rename_editor, cx| {
let rename_selection = rename_editor.selections.newest::<usize>(cx);
let rename_selection = rename_editor.selections.newest::<usize>(&rename_editor.display_snapshot(cx));
assert_eq!(
rename_selection.range(),
1..2,
Expand Down
Loading
Loading