Skip to content

Commit 33c4afe

Browse files
bors[bot]matklad
andauthored
Merge #5880
5880: Opportunistically check indel overlap r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 3f72168 + 7239d8c commit 33c4afe

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

crates/text_edit/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ impl<'a> IntoIterator for &'a TextEdit {
159159

160160
impl TextEditBuilder {
161161
pub fn replace(&mut self, range: TextRange, replace_with: String) {
162-
self.indels.push(Indel::replace(range, replace_with))
162+
self.indel(Indel::replace(range, replace_with))
163163
}
164164
pub fn delete(&mut self, range: TextRange) {
165-
self.indels.push(Indel::delete(range))
165+
self.indel(Indel::delete(range))
166166
}
167167
pub fn insert(&mut self, offset: TextSize, text: String) {
168-
self.indels.push(Indel::insert(offset, text))
168+
self.indel(Indel::insert(offset, text))
169169
}
170170
pub fn finish(self) -> TextEdit {
171171
let mut indels = self.indels;
@@ -175,6 +175,12 @@ impl TextEditBuilder {
175175
pub fn invalidates_offset(&self, offset: TextSize) -> bool {
176176
self.indels.iter().any(|indel| indel.delete.contains_inclusive(offset))
177177
}
178+
fn indel(&mut self, indel: Indel) {
179+
self.indels.push(indel);
180+
if self.indels.len() <= 16 {
181+
check_disjoint(&mut self.indels);
182+
}
183+
}
178184
}
179185

180186
fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {

0 commit comments

Comments
 (0)