aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/edit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/src/edit.rs')
-rw-r--r--crates/libeditor/src/edit.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/libeditor/src/edit.rs b/crates/libeditor/src/edit.rs
index dcf1ee81e..09cf2bd00 100644
--- a/crates/libeditor/src/edit.rs
+++ b/crates/libeditor/src/edit.rs
@@ -1,5 +1,8 @@
1use {TextRange, TextUnit}; 1use {TextRange, TextUnit};
2use libsyntax2::AtomEdit; 2use libsyntax2::{
3 AtomEdit,
4 text_utils::contains_offset_nonstrict,
5};
3 6
4#[derive(Debug, Clone)] 7#[derive(Debug, Clone)]
5pub struct Edit { 8pub struct Edit {
@@ -15,19 +18,15 @@ impl EditBuilder {
15 pub fn new() -> EditBuilder { 18 pub fn new() -> EditBuilder {
16 EditBuilder { atoms: Vec::new() } 19 EditBuilder { atoms: Vec::new() }
17 } 20 }
18
19 pub fn replace(&mut self, range: TextRange, replace_with: String) { 21 pub fn replace(&mut self, range: TextRange, replace_with: String) {
20 self.atoms.push(AtomEdit::replace(range, replace_with)) 22 self.atoms.push(AtomEdit::replace(range, replace_with))
21 } 23 }
22
23 pub fn delete(&mut self, range: TextRange) { 24 pub fn delete(&mut self, range: TextRange) {
24 self.atoms.push(AtomEdit::delete(range)) 25 self.atoms.push(AtomEdit::delete(range))
25 } 26 }
26
27 pub fn insert(&mut self, offset: TextUnit, text: String) { 27 pub fn insert(&mut self, offset: TextUnit, text: String) {
28 self.atoms.push(AtomEdit::insert(offset, text)) 28 self.atoms.push(AtomEdit::insert(offset, text))
29 } 29 }
30
31 pub fn finish(self) -> Edit { 30 pub fn finish(self) -> Edit {
32 let mut atoms = self.atoms; 31 let mut atoms = self.atoms;
33 atoms.sort_by_key(|a| a.delete.start()); 32 atoms.sort_by_key(|a| a.delete.start());
@@ -36,6 +35,9 @@ impl EditBuilder {
36 } 35 }
37 Edit { atoms } 36 Edit { atoms }
38 } 37 }
38 pub fn invalidates_offset(&self, offset: TextUnit) -> bool {
39 self.atoms.iter().any(|atom| contains_offset_nonstrict(atom.delete, offset))
40 }
39} 41}
40 42
41impl Edit { 43impl Edit {