aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/edit.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-15 21:24:20 +0100
committerAleksey Kladov <[email protected]>2018-08-15 21:24:20 +0100
commitaa0d344581dcfd7f18c595688a4b2709b0f2421e (patch)
tree9846f587dcad204e6744ca5ff37faccf4251104c /crates/libeditor/src/edit.rs
parenta7d31b55a4292f55851bc75265643b2ae2e675df (diff)
Edits with cursors
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 {