aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_text_edit/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_text_edit/src/lib.rs')
-rw-r--r--crates/ra_text_edit/src/lib.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs
new file mode 100644
index 000000000..789471e8a
--- /dev/null
+++ b/crates/ra_text_edit/src/lib.rs
@@ -0,0 +1,29 @@
1mod edit;
2pub mod text_utils;
3
4pub use crate::edit::{Edit, EditBuilder};
5
6use text_unit::{TextRange, TextUnit};
7
8#[derive(Debug, Clone)]
9pub struct AtomEdit {
10 pub delete: TextRange,
11 pub insert: String,
12}
13
14impl AtomEdit {
15 pub fn replace(range: TextRange, replace_with: String) -> AtomEdit {
16 AtomEdit {
17 delete: range,
18 insert: replace_with,
19 }
20 }
21
22 pub fn delete(range: TextRange) -> AtomEdit {
23 AtomEdit::replace(range, String::new())
24 }
25
26 pub fn insert(offset: TextUnit, text: String) -> AtomEdit {
27 AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text)
28 }
29}