diff options
Diffstat (limited to 'crates/ra_text_edit')
-rw-r--r-- | crates/ra_text_edit/src/text_edit.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/ra_text_edit/src/text_edit.rs b/crates/ra_text_edit/src/text_edit.rs index 0381ea000..413c7d782 100644 --- a/crates/ra_text_edit/src/text_edit.rs +++ b/crates/ra_text_edit/src/text_edit.rs | |||
@@ -32,6 +32,24 @@ impl TextEditBuilder { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | impl TextEdit { | 34 | impl TextEdit { |
35 | pub fn insert(offset: TextUnit, text: String) -> TextEdit { | ||
36 | let mut builder = TextEditBuilder::default(); | ||
37 | builder.insert(offset, text); | ||
38 | builder.finish() | ||
39 | } | ||
40 | |||
41 | pub fn delete(range: TextRange) -> TextEdit { | ||
42 | let mut builder = TextEditBuilder::default(); | ||
43 | builder.delete(range); | ||
44 | builder.finish() | ||
45 | } | ||
46 | |||
47 | pub fn replace(range: TextRange, replace_with: String) -> TextEdit { | ||
48 | let mut builder = TextEditBuilder::default(); | ||
49 | builder.replace(range, replace_with); | ||
50 | builder.finish() | ||
51 | } | ||
52 | |||
35 | pub(crate) fn from_atoms(mut atoms: Vec<AtomTextEdit>) -> TextEdit { | 53 | pub(crate) fn from_atoms(mut atoms: Vec<AtomTextEdit>) -> TextEdit { |
36 | atoms.sort_by_key(|a| (a.delete.start(), a.delete.end())); | 54 | atoms.sort_by_key(|a| (a.delete.start(), a.delete.end())); |
37 | for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) { | 55 | for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) { |