rust/crates/ra_text_edit/src/lib.rs
Aleksey Kladov 57140f1730 Drop proptest tests
It takes waaay to long to compile.

We should add quickcheck tests when we touch the relevant code next
time.
2020-02-17 16:57:06 +01:00

37 lines
1002 B
Rust

//! FIXME: write short doc here
mod text_edit;
use text_unit::{TextRange, TextUnit};
pub use crate::text_edit::{TextEdit, TextEditBuilder};
/// Must not overlap with other `AtomTextEdit`s
#[derive(Debug, Clone)]
pub struct AtomTextEdit {
/// Refers to offsets in the original text
pub delete: TextRange,
pub insert: String,
}
impl AtomTextEdit {
pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit {
AtomTextEdit { delete: range, insert: replace_with }
}
pub fn delete(range: TextRange) -> AtomTextEdit {
AtomTextEdit::replace(range, String::new())
}
pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit {
AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text)
}
pub fn apply(&self, mut text: String) -> String {
let start = self.delete.start().to_usize();
let end = self.delete.end().to_usize();
text.replace_range(start..end, &self.insert);
text
}
}