Create blocks with anchors to allow a bias to be specified

This allows us to respect the bias on anchors we use to create excerpt headers so that they always remain above any content inserted at the start of an excerpt.
This commit is contained in:
Nathan Sobo
2021-12-30 01:03:19 -08:00
parent 984378e12c
commit 6d6a82655a
3 changed files with 23 additions and 29 deletions
+6 -8
View File
@@ -2972,7 +2972,7 @@ impl Editor {
let message_height = diagnostic.message.lines().count() as u8;
BlockProperties {
position: entry.range.start,
position: buffer.anchor_after(entry.range.start),
height: message_height,
render: diagnostic_block_renderer(diagnostic, true, build_settings),
disposition: BlockDisposition::Below,
@@ -3431,14 +3431,11 @@ impl Editor {
}
}
pub fn insert_blocks<P>(
pub fn insert_blocks(
&mut self,
blocks: impl IntoIterator<Item = BlockProperties<P>>,
blocks: impl IntoIterator<Item = BlockProperties<Anchor>>,
cx: &mut ViewContext<Self>,
) -> Vec<BlockId>
where
P: ToOffset + Clone,
{
) -> Vec<BlockId> {
let blocks = self
.display_map
.update(cx, |display_map, cx| display_map.insert_blocks(blocks, cx));
@@ -5140,12 +5137,13 @@ mod tests {
fn test_move_line_up_down_with_blocks(cx: &mut gpui::MutableAppContext) {
let settings = EditorSettings::test(&cx);
let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx);
let snapshot = buffer.read(cx).snapshot(cx);
let (_, editor) =
cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx));
editor.update(cx, |editor, cx| {
editor.insert_blocks(
[BlockProperties {
position: Point::new(2, 0),
position: snapshot.anchor_after(Point::new(2, 0)),
disposition: BlockDisposition::Below,
height: 1,
render: Arc::new(|_| Empty::new().boxed()),