Re-resolve anchor before applying AI inline assist edits (#43103)
Closes #39088 Release Notes: - Fixed AI assistant edits being scrambled when file was modified while it was open -- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
co-authored by
Conrad Irwin
parent
18f14a6ebf
commit
d6d967f443
@@ -491,6 +491,14 @@ impl CodegenAlternative {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let start_time = Instant::now();
|
||||
|
||||
// Make a new snapshot and re-resolve anchor in case the document was modified.
|
||||
// This can happen often if the editor loses focus and is saved + reformatted,
|
||||
// as in https://github.com/zed-industries/zed/issues/39088
|
||||
self.snapshot = self.buffer.read(cx).snapshot(cx);
|
||||
self.range = self.snapshot.anchor_after(self.range.start)
|
||||
..self.snapshot.anchor_after(self.range.end);
|
||||
|
||||
let snapshot = self.snapshot.clone();
|
||||
let selected_text = snapshot
|
||||
.text_for_range(self.range.start..self.range.end)
|
||||
|
||||
Reference in New Issue
Block a user