2019-09-30 08:58:53 +00:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2018-12-11 18:07:17 +00:00
|
|
|
mod text_edit;
|
2018-12-10 21:09:12 +00:00
|
|
|
|
2020-04-24 21:40:41 +00:00
|
|
|
use text_size::{TextRange, TextSize};
|
2018-12-10 21:09:12 +00:00
|
|
|
|
2020-02-17 15:57:06 +00:00
|
|
|
pub use crate::text_edit::{TextEdit, TextEditBuilder};
|
|
|
|
|
2018-12-23 14:49:14 +00:00
|
|
|
/// Must not overlap with other `AtomTextEdit`s
|
2018-12-10 21:09:12 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2018-12-11 18:07:17 +00:00
|
|
|
pub struct AtomTextEdit {
|
2018-12-23 14:49:14 +00:00
|
|
|
/// Refers to offsets in the original text
|
2018-12-10 21:09:12 +00:00
|
|
|
pub delete: TextRange,
|
|
|
|
pub insert: String,
|
|
|
|
}
|
|
|
|
|
2018-12-11 18:07:17 +00:00
|
|
|
impl AtomTextEdit {
|
|
|
|
pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit {
|
2019-02-08 11:49:43 +00:00
|
|
|
AtomTextEdit { delete: range, insert: replace_with }
|
2018-12-10 21:09:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 18:07:17 +00:00
|
|
|
pub fn delete(range: TextRange) -> AtomTextEdit {
|
|
|
|
AtomTextEdit::replace(range, String::new())
|
2018-12-10 21:09:12 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:40:41 +00:00
|
|
|
pub fn insert(offset: TextSize, text: String) -> AtomTextEdit {
|
|
|
|
AtomTextEdit::replace(TextRange::empty(offset), text)
|
2018-12-10 21:09:12 +00:00
|
|
|
}
|
2019-01-08 18:59:55 +00:00
|
|
|
|
|
|
|
pub fn apply(&self, mut text: String) -> String {
|
2020-04-24 21:40:41 +00:00
|
|
|
let start: usize = self.delete.start().into();
|
|
|
|
let end: usize = self.delete.end().into();
|
2019-01-08 18:59:55 +00:00
|
|
|
text.replace_range(start..end, &self.insert);
|
|
|
|
text
|
|
|
|
}
|
2018-12-10 21:09:12 +00:00
|
|
|
}
|