aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_text_edit/src/lib.rs
blob: 789471e8a282523ce142f116ee2ec3ff2c7d0247 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)
    }
}