Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix panic when accepting completions (#11762)

Conrad Irwincf97b995b2a6
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 460b9d5340b..6924a9b9884 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -4670,12 +4670,11 @@ impl Editor {
delta +=
snippet.text.len() as isize - insertion_range.len() as isize;
- let start = snapshot.anchor_before(
- (insertion_start + tabstop_range.start) as usize,
- );
- let end = snapshot
- .anchor_after((insertion_start + tabstop_range.end) as usize);
- start..end
+ let start = ((insertion_start + tabstop_range.start) as usize)
+ .min(snapshot.len());
+ let end = ((insertion_start + tabstop_range.end) as usize)
+ .min(snapshot.len());
+ snapshot.anchor_before(start)..snapshot.anchor_after(end)
})
})
.collect::<Vec<_>>();