extract AtomEdit and Edit into new ra_text_edit crate

This commit is contained in:
Bernardo 2018-12-10 22:09:12 +01:00
parent f655f993fe
commit 7344d28768
19 changed files with 81 additions and 40 deletions

View file

@ -0,0 +1,29 @@
mod edit;
pub mod text_utils;
pub use crate::edit::{Edit, EditBuilder};
use text_unit::{TextRange, TextUnit};
#[derive(Debug, Clone)]
pub struct AtomEdit {
pub delete: TextRange,
pub insert: String,
}
impl AtomEdit {
pub fn replace(range: TextRange, replace_with: String) -> AtomEdit {
AtomEdit {
delete: range,
insert: replace_with,
}
}
pub fn delete(range: TextRange) -> AtomEdit {
AtomEdit::replace(range, String::new())
}
pub fn insert(offset: TextUnit, text: String) -> AtomEdit {
AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text)
}
}