2018-12-11 12:07:17 -06:00
|
|
|
mod text_edit;
|
2018-12-10 15:09:12 -06:00
|
|
|
pub mod text_utils;
|
2018-12-12 11:51:43 -06:00
|
|
|
pub mod test_utils;
|
2018-12-10 15:09:12 -06:00
|
|
|
|
2018-12-11 12:07:17 -06:00
|
|
|
pub use crate::text_edit::{TextEdit, TextEditBuilder};
|
2018-12-10 15:09:12 -06:00
|
|
|
|
|
|
|
use text_unit::{TextRange, TextUnit};
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2018-12-11 12:07:17 -06:00
|
|
|
pub struct AtomTextEdit {
|
2018-12-10 15:09:12 -06:00
|
|
|
pub delete: TextRange,
|
|
|
|
pub insert: String,
|
|
|
|
}
|
|
|
|
|
2018-12-11 12:07:17 -06:00
|
|
|
impl AtomTextEdit {
|
|
|
|
pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit {
|
|
|
|
AtomTextEdit {
|
2018-12-10 15:09:12 -06:00
|
|
|
delete: range,
|
|
|
|
insert: replace_with,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 12:07:17 -06:00
|
|
|
pub fn delete(range: TextRange) -> AtomTextEdit {
|
|
|
|
AtomTextEdit::replace(range, String::new())
|
2018-12-10 15:09:12 -06:00
|
|
|
}
|
|
|
|
|
2018-12-11 12:07:17 -06:00
|
|
|
pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit {
|
|
|
|
AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text)
|
2018-12-10 15:09:12 -06:00
|
|
|
}
|
|
|
|
}
|