diff options
Diffstat (limited to 'crates/ra_text_edit/src/lib.rs')
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 29 |
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..13e20f6fb --- /dev/null +++ b/crates/ra_text_edit/src/lib.rs | |||
@@ -0,0 +1,29 @@ | |||
1 | mod text_edit; | ||
2 | pub mod text_utils; | ||
3 | |||
4 | pub use crate::text_edit::{TextEdit, TextEditBuilder}; | ||
5 | |||
6 | use text_unit::{TextRange, TextUnit}; | ||
7 | |||
8 | #[derive(Debug, Clone)] | ||
9 | pub struct AtomTextEdit { | ||
10 | pub delete: TextRange, | ||
11 | pub insert: String, | ||
12 | } | ||
13 | |||
14 | impl AtomTextEdit { | ||
15 | pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit { | ||
16 | AtomTextEdit { | ||
17 | delete: range, | ||
18 | insert: replace_with, | ||
19 | } | ||
20 | } | ||
21 | |||
22 | pub fn delete(range: TextRange) -> AtomTextEdit { | ||
23 | AtomTextEdit::replace(range, String::new()) | ||
24 | } | ||
25 | |||
26 | pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit { | ||
27 | AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text) | ||
28 | } | ||
29 | } | ||