aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-25 17:01:47 +0100
committerGitHub <[email protected]>2020-08-25 17:01:47 +0100
commit33c4afeae085b182a89cf8acea4d3eb193318c92 (patch)
tree69e9ac083b084beca1920e60e7abf528861a06f5 /crates
parent3f721683deb81c015484abd14eb67b96f39b1aff (diff)
parent7239d8ca951593b66a557c989dffaf94edddf420 (diff)
Merge #5880
5880: Opportunistically check indel overlap r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/text_edit/src/lib.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/text_edit/src/lib.rs b/crates/text_edit/src/lib.rs
index ab8cd7fd1..e417e8ea6 100644
--- a/crates/text_edit/src/lib.rs
+++ b/crates/text_edit/src/lib.rs
@@ -159,13 +159,13 @@ impl<'a> IntoIterator for &'a TextEdit {
159 159
160impl TextEditBuilder { 160impl TextEditBuilder {
161 pub fn replace(&mut self, range: TextRange, replace_with: String) { 161 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))
163 } 163 }
164 pub fn delete(&mut self, range: TextRange) { 164 pub fn delete(&mut self, range: TextRange) {
165 self.indels.push(Indel::delete(range)) 165 self.indel(Indel::delete(range))
166 } 166 }
167 pub fn insert(&mut self, offset: TextSize, text: String) { 167 pub fn insert(&mut self, offset: TextSize, text: String) {
168 self.indels.push(Indel::insert(offset, text)) 168 self.indel(Indel::insert(offset, text))
169 } 169 }
170 pub fn finish(self) -> TextEdit { 170 pub fn finish(self) -> TextEdit {
171 let mut indels = self.indels; 171 let mut indels = self.indels;
@@ -175,6 +175,12 @@ impl TextEditBuilder {
175 pub fn invalidates_offset(&self, offset: TextSize) -> bool { 175 pub fn invalidates_offset(&self, offset: TextSize) -> bool {
176 self.indels.iter().any(|indel| indel.delete.contains_inclusive(offset)) 176 self.indels.iter().any(|indel| indel.delete.contains_inclusive(offset))
177 } 177 }
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 }
178} 184}
179 185
180fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool { 186fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {