Fix alignment of blocks adjacent to other blocks

Nathan Sobo and Max Brunsfeld created

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>

Change summary

crates/editor/src/display_map/block_map.rs |  4 ++--
crates/editor/src/element.rs               | 13 +++++++------
2 files changed, 9 insertions(+), 8 deletions(-)

Detailed changes

crates/editor/src/display_map/block_map.rs 🔗

@@ -827,8 +827,8 @@ impl AlignedBlock {
         self.render.lock()(cx)
     }
 
-    pub fn disposition(&self) -> BlockDisposition {
-        self.block.disposition
+    pub fn position(&self) -> &Anchor {
+        &self.block.position
     }
 }
 

crates/editor/src/element.rs 🔗

@@ -1,4 +1,4 @@
-use crate::display_map::{BlockContext, BlockDisposition};
+use crate::display_map::{BlockContext, ToDisplayPoint};
 
 use super::{
     DisplayPoint, Editor, EditorMode, EditorSettings, EditorStyle, Input, Scroll, Select,
@@ -19,7 +19,7 @@ use gpui::{
     MutableAppContext, PaintContext, Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle,
 };
 use json::json;
-use language::Chunk;
+use language::{Chunk, ToPoint};
 use smallvec::SmallVec;
 use std::{
     cmp::{self, Ordering},
@@ -633,10 +633,11 @@ impl EditorElement {
         snapshot
             .blocks_in_range(rows.clone())
             .map(|(start_row, block)| {
-                let anchor_row = match block.disposition() {
-                    BlockDisposition::Above => start_row + block.height(),
-                    BlockDisposition::Below => start_row - 1,
-                };
+                let anchor_row = block
+                    .position()
+                    .to_point(&snapshot.buffer_snapshot)
+                    .to_display_point(snapshot)
+                    .row();
 
                 let anchor_x = if rows.contains(&anchor_row) {
                     line_layouts[(anchor_row - rows.start) as usize]