mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
extract AtomEdit and Edit into new ra_text_edit crate
This commit is contained in:
parent
f655f993fe
commit
7344d28768
19 changed files with 81 additions and 40 deletions
29
crates/ra_text_edit/src/lib.rs
Normal file
29
crates/ra_text_edit/src/lib.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue