aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_text_edit/src/text_edit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_text_edit/src/text_edit.rs')
-rw-r--r--crates/ra_text_edit/src/text_edit.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/crates/ra_text_edit/src/text_edit.rs b/crates/ra_text_edit/src/text_edit.rs
index 392968d63..0881f3e1c 100644
--- a/crates/ra_text_edit/src/text_edit.rs
+++ b/crates/ra_text_edit/src/text_edit.rs
@@ -26,12 +26,7 @@ impl TextEditBuilder {
26 self.atoms.push(AtomTextEdit::insert(offset, text)) 26 self.atoms.push(AtomTextEdit::insert(offset, text))
27 } 27 }
28 pub fn finish(self) -> TextEdit { 28 pub fn finish(self) -> TextEdit {
29 let mut atoms = self.atoms; 29 TextEdit::from_atoms(self.atoms)
30 atoms.sort_by_key(|a| (a.delete.start(), a.delete.end()));
31 for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) {
32 assert!(a1.delete.end() <= a2.delete.start())
33 }
34 TextEdit { atoms }
35 } 30 }
36 pub fn invalidates_offset(&self, offset: TextUnit) -> bool { 31 pub fn invalidates_offset(&self, offset: TextUnit) -> bool {
37 self.atoms 32 self.atoms
@@ -41,6 +36,14 @@ impl TextEditBuilder {
41} 36}
42 37
43impl TextEdit { 38impl TextEdit {
39 pub(crate) fn from_atoms(mut atoms: Vec<AtomTextEdit>) -> TextEdit {
40 atoms.sort_by_key(|a| (a.delete.start(), a.delete.end()));
41 for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) {
42 assert!(a1.delete.end() <= a2.delete.start())
43 }
44 TextEdit { atoms }
45 }
46
44 pub fn as_atoms(&self) -> &[AtomTextEdit] { 47 pub fn as_atoms(&self) -> &[AtomTextEdit] {
45 &self.atoms 48 &self.atoms
46 } 49 }