Start on copy-paste

This commit is contained in:
Antonio Scandurra
2021-04-13 14:58:10 +02:00
parent 7469240a2e
commit f4c1ffc329
6 changed files with 87 additions and 9 deletions
+7 -8
View File
@@ -563,10 +563,13 @@ impl Buffer {
self.chars().collect()
}
pub fn text_for_range<T: ToOffset>(&self, range: Range<T>) -> Result<String> {
pub fn text_for_range<'a, T: ToOffset>(
&'a self,
range: Range<T>,
) -> Result<impl 'a + Iterator<Item = char>> {
let start = range.start.to_offset(self)?;
let end = range.end.to_offset(self)?;
Ok(self.chars_at(start)?.take(end - start).collect())
Ok(self.chars_at(start)?.take(end - start))
}
pub fn chars(&self) -> CharIter {
@@ -2470,13 +2473,9 @@ mod tests {
let old_len = old_range.end - old_range.start;
let new_len = new_range.end - new_range.start;
let old_start = (old_range.start as isize + delta) as usize;
let new_text: String = buffer.text_for_range(new_range).unwrap().collect();
old_buffer
.edit(
Some(old_start..old_start + old_len),
buffer.text_for_range(new_range).unwrap(),
None,
)
.edit(Some(old_start..old_start + old_len), new_text, None)
.unwrap();
delta += new_len as isize - old_len as isize;