aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/edit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/src/edit.rs')
-rw-r--r--crates/libeditor/src/edit.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/libeditor/src/edit.rs b/crates/libeditor/src/edit.rs
index 15a2a904f..3edd0809d 100644
--- a/crates/libeditor/src/edit.rs
+++ b/crates/libeditor/src/edit.rs
@@ -67,6 +67,21 @@ impl Edit {
67 assert_eq!(buf.len(), total_len); 67 assert_eq!(buf.len(), total_len);
68 buf 68 buf
69 } 69 }
70
71 pub fn apply_to_offset(&self, offset: TextUnit) -> Option<TextUnit> {
72 let mut res = offset;
73 for atom in self.atoms.iter() {
74 if atom.delete.start() >= offset {
75 break;
76 }
77 if offset < atom.delete.end() {
78 return None
79 }
80 res += TextUnit::of_str(&atom.insert);
81 res -= atom.delete.len();
82 }
83 Some(res)
84 }
70} 85}
71 86
72impl AtomEdit { 87impl AtomEdit {