Merge pull request #1234 from zed-industries/fix-editor-cloning

Clone fold and selection state correctly when splitting an editor
This commit is contained in:
Max Brunsfeld 2022-06-23 13:27:40 -07:00 committed by GitHub
commit c91451a1b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 30 deletions

View file

@ -3,7 +3,7 @@ mod fold_map;
mod tab_map;
mod wrap_map;
use crate::{Anchor, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};
use crate::{Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};
use block_map::{BlockMap, BlockPoint};
use collections::{HashMap, HashSet};
use fold_map::FoldMap;
@ -97,6 +97,15 @@ impl DisplayMap {
}
}
pub fn set_state(&mut self, other: &DisplaySnapshot, cx: &mut ModelContext<Self>) {
self.fold(
other
.folds_in_range(0..other.buffer_snapshot.len())
.map(|fold| fold.to_offset(&other.buffer_snapshot)),
cx,
);
}
pub fn fold<T: ToOffset>(
&mut self,
ranges: impl IntoIterator<Item = Range<T>>,