Implement edit rejection in ActionLog (#28080)

Release Notes:

- Fixed a bug that would prevent rejecting certain agent edits.
This commit is contained in:
Antonio Scandurra 2025-04-04 13:20:18 +02:00 committed by GitHub
parent 5e286897d3
commit 277a3f8d6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 368 additions and 39 deletions

View file

@ -3,7 +3,7 @@ use anyhow::Result;
use buffer_diff::DiffHunkStatus;
use collections::HashSet;
use editor::{
AnchorRangeExt, Direction, Editor, EditorEvent, MultiBuffer, ToPoint,
Direction, Editor, EditorEvent, MultiBuffer, ToPoint,
actions::{GoToHunk, GoToPreviousHunk},
scroll::Autoscroll,
};
@ -350,13 +350,16 @@ impl AgentDiff {
self.update_selection(&diff_hunks_in_ranges, window, cx);
}
let point_ranges = ranges
.into_iter()
.map(|range| range.to_point(&snapshot))
.collect();
self.editor.update(cx, |editor, cx| {
editor.restore_hunks_in_ranges(point_ranges, window, cx)
});
for hunk in &diff_hunks_in_ranges {
let buffer = self.multibuffer.read(cx).buffer(hunk.buffer_id);
if let Some(buffer) = buffer {
self.thread
.update(cx, |thread, cx| {
thread.reject_edits_in_range(buffer, hunk.buffer_range.clone(), cx)
})
.detach_and_log_err(cx);
}
}
}
fn update_selection(
@ -986,7 +989,7 @@ mod tests {
Point::new(3, 0)..Point::new(3, 0)
);
// Restoring a hunk also moves the cursor to the next hunk, possibly cycling if it's at the end.
// Rejecting a hunk also moves the cursor to the next hunk, possibly cycling if it's at the end.
editor.update_in(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |selections| {
selections.select_ranges([Point::new(10, 0)..Point::new(10, 0)])