mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-01 05:15:19 +03:00
WIP: Insert blocks in BlockMap
for MultiBuffer
headers
This commit is contained in:
parent
8534a9cc41
commit
91c786a8db
@ -345,7 +345,7 @@ mod tests {
|
|||||||
view.update(cx, |view, cx| {
|
view.update(cx, |view, cx| {
|
||||||
view.populate_excerpts(buffer, cx);
|
view.populate_excerpts(buffer, cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
view.excerpts.read(cx).read(cx).text(),
|
view.editor.update(cx, |editor, cx| editor.display_text(cx)),
|
||||||
concat!(
|
concat!(
|
||||||
"\n", // primary diagnostic message
|
"\n", // primary diagnostic message
|
||||||
"\n", // filename
|
"\n", // filename
|
||||||
|
@ -3,9 +3,7 @@ mod fold_map;
|
|||||||
mod tab_map;
|
mod tab_map;
|
||||||
mod wrap_map;
|
mod wrap_map;
|
||||||
|
|
||||||
use crate::{
|
use crate::{Anchor, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};
|
||||||
multi_buffer::RenderHeaderFn, Anchor, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint,
|
|
||||||
};
|
|
||||||
use block_map::{BlockMap, BlockPoint};
|
use block_map::{BlockMap, BlockPoint};
|
||||||
use fold_map::{FoldMap, ToFoldPoint as _};
|
use fold_map::{FoldMap, ToFoldPoint as _};
|
||||||
use gpui::{fonts::FontId, Entity, ModelContext, ModelHandle};
|
use gpui::{fonts::FontId, Entity, ModelContext, ModelHandle};
|
||||||
@ -344,22 +342,6 @@ impl DisplaySnapshot {
|
|||||||
self.blocks_snapshot.blocks_in_range(rows)
|
self.blocks_snapshot.blocks_in_range(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn excerpt_headers_in_range<'a>(
|
|
||||||
&'a self,
|
|
||||||
rows: Range<u32>,
|
|
||||||
) -> impl 'a + Iterator<Item = (Range<u32>, RenderHeaderFn)> {
|
|
||||||
todo!();
|
|
||||||
let start_row = DisplayPoint::new(rows.start, 0).to_point(self).row;
|
|
||||||
let end_row = DisplayPoint::new(rows.end, 0).to_point(self).row;
|
|
||||||
self.buffer_snapshot
|
|
||||||
.excerpt_headers_in_range(start_row..end_row)
|
|
||||||
.map(move |(row, header_height, render)| {
|
|
||||||
let start_row = Point::new(rows.start, 0).to_display_point(self).row();
|
|
||||||
let end_row = Point::new(rows.end, 0).to_display_point(self).row();
|
|
||||||
(start_row..end_row, render)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn intersects_fold<T: ToOffset>(&self, offset: T) -> bool {
|
pub fn intersects_fold<T: ToOffset>(&self, offset: T) -> bool {
|
||||||
self.folds_snapshot.intersects_fold(offset)
|
self.folds_snapshot.intersects_fold(offset)
|
||||||
}
|
}
|
||||||
|
@ -227,8 +227,9 @@ impl BlockMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the blocks within this edited region.
|
// Find the blocks within this edited region.
|
||||||
let new_start = wrap_snapshot.to_point(WrapPoint::new(new_start.0, 0), Bias::Left);
|
let new_buffer_start =
|
||||||
let start_anchor = buffer.anchor_before(new_start);
|
wrap_snapshot.to_point(WrapPoint::new(new_start.0, 0), Bias::Left);
|
||||||
|
let start_anchor = buffer.anchor_before(new_buffer_start);
|
||||||
let start_block_ix = match self.blocks[last_block_ix..].binary_search_by(|probe| {
|
let start_block_ix = match self.blocks[last_block_ix..].binary_search_by(|probe| {
|
||||||
probe
|
probe
|
||||||
.position
|
.position
|
||||||
@ -238,11 +239,14 @@ impl BlockMap {
|
|||||||
}) {
|
}) {
|
||||||
Ok(ix) | Err(ix) => last_block_ix + ix,
|
Ok(ix) | Err(ix) => last_block_ix + ix,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let new_buffer_end;
|
||||||
let end_block_ix = if new_end.0 > wrap_snapshot.max_point().row() {
|
let end_block_ix = if new_end.0 > wrap_snapshot.max_point().row() {
|
||||||
|
new_buffer_end = wrap_snapshot.buffer_snapshot().max_point() + Point::new(1, 0);
|
||||||
self.blocks.len()
|
self.blocks.len()
|
||||||
} else {
|
} else {
|
||||||
let new_end = wrap_snapshot.to_point(WrapPoint::new(new_end.0, 0), Bias::Left);
|
new_buffer_end = wrap_snapshot.to_point(WrapPoint::new(new_end.0, 0), Bias::Left);
|
||||||
let end_anchor = buffer.anchor_before(new_end);
|
let end_anchor = buffer.anchor_before(new_buffer_end);
|
||||||
match self.blocks[start_block_ix..].binary_search_by(|probe| {
|
match self.blocks[start_block_ix..].binary_search_by(|probe| {
|
||||||
probe
|
probe
|
||||||
.position
|
.position
|
||||||
@ -254,7 +258,26 @@ impl BlockMap {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
last_block_ix = end_block_ix;
|
last_block_ix = end_block_ix;
|
||||||
blocks_in_edit.clear();
|
|
||||||
|
debug_assert!(blocks_in_edit.is_empty());
|
||||||
|
blocks_in_edit.extend(
|
||||||
|
wrap_snapshot
|
||||||
|
.buffer_snapshot()
|
||||||
|
.excerpt_headers_in_range(new_buffer_start.row..new_buffer_end.row)
|
||||||
|
.map(|(start_row, header_height, render_header)| {
|
||||||
|
(
|
||||||
|
start_row,
|
||||||
|
0,
|
||||||
|
Arc::new(Block {
|
||||||
|
id: Default::default(),
|
||||||
|
position: Anchor::min(),
|
||||||
|
height: header_height,
|
||||||
|
render: Mutex::new(Arc::new(move |cx| render_header(cx))),
|
||||||
|
disposition: BlockDisposition::Above,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
);
|
||||||
blocks_in_edit.extend(
|
blocks_in_edit.extend(
|
||||||
self.blocks[start_block_ix..end_block_ix]
|
self.blocks[start_block_ix..end_block_ix]
|
||||||
.iter()
|
.iter()
|
||||||
@ -268,22 +291,21 @@ impl BlockMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let position = wrap_snapshot.from_point(position, Bias::Left);
|
let position = wrap_snapshot.from_point(position, Bias::Left);
|
||||||
(position.row(), column, block)
|
(position.row(), column, block.clone())
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
blocks_in_edit
|
blocks_in_edit.sort_by_key(|(row, _, block)| (*row, block.disposition, block.id));
|
||||||
.sort_unstable_by_key(|(row, _, block)| (*row, block.disposition, block.id));
|
|
||||||
|
|
||||||
// For each of these blocks, insert a new isomorphic transform preceding the block,
|
// For each of these blocks, insert a new isomorphic transform preceding the block,
|
||||||
// and then insert the block itself.
|
// and then insert the block itself.
|
||||||
for (block_row, column, block) in blocks_in_edit.iter().copied() {
|
for (block_row, column, block) in blocks_in_edit.drain(..) {
|
||||||
let insertion_row = match block.disposition {
|
let insertion_row = match block.disposition {
|
||||||
BlockDisposition::Above => block_row,
|
BlockDisposition::Above => block_row,
|
||||||
BlockDisposition::Below => block_row + 1,
|
BlockDisposition::Below => block_row + 1,
|
||||||
};
|
};
|
||||||
let extent_before_block = insertion_row - new_transforms.summary().input_rows;
|
let extent_before_block = insertion_row - new_transforms.summary().input_rows;
|
||||||
push_isomorphic(&mut new_transforms, extent_before_block);
|
push_isomorphic(&mut new_transforms, extent_before_block);
|
||||||
new_transforms.push(Transform::block(block.clone(), column), &());
|
new_transforms.push(Transform::block(block, column), &());
|
||||||
}
|
}
|
||||||
|
|
||||||
old_end = WrapRow(old_end.0.min(old_row_count));
|
old_end = WrapRow(old_end.0.min(old_row_count));
|
||||||
|
@ -631,55 +631,34 @@ impl EditorElement {
|
|||||||
line_layouts: &[text_layout::Line],
|
line_layouts: &[text_layout::Line],
|
||||||
cx: &mut LayoutContext,
|
cx: &mut LayoutContext,
|
||||||
) -> Vec<(u32, ElementBox)> {
|
) -> Vec<(u32, ElementBox)> {
|
||||||
let mut blocks = Vec::new();
|
snapshot
|
||||||
|
.blocks_in_range(rows.clone())
|
||||||
|
.map(|(start_row, block)| {
|
||||||
|
let anchor_row = block
|
||||||
|
.position()
|
||||||
|
.to_point(&snapshot.buffer_snapshot)
|
||||||
|
.to_display_point(snapshot)
|
||||||
|
.row();
|
||||||
|
|
||||||
blocks.extend(
|
let anchor_x = if rows.contains(&anchor_row) {
|
||||||
snapshot
|
line_layouts[(anchor_row - rows.start) as usize]
|
||||||
.blocks_in_range(rows.clone())
|
.x_for_index(block.column() as usize)
|
||||||
.map(|(start_row, block)| {
|
} else {
|
||||||
let anchor_row = block
|
layout_line(anchor_row, snapshot, style, cx.text_layout_cache)
|
||||||
.position()
|
.x_for_index(block.column() as usize)
|
||||||
.to_point(&snapshot.buffer_snapshot)
|
};
|
||||||
.to_display_point(snapshot)
|
|
||||||
.row();
|
|
||||||
|
|
||||||
let anchor_x = if rows.contains(&anchor_row) {
|
let mut element = block.render(&BlockContext { cx, anchor_x });
|
||||||
line_layouts[(anchor_row - rows.start) as usize]
|
element.layout(
|
||||||
.x_for_index(block.column() as usize)
|
SizeConstraint {
|
||||||
} else {
|
min: Vector2F::zero(),
|
||||||
layout_line(anchor_row, snapshot, style, cx.text_layout_cache)
|
max: vec2f(text_width, block.height() as f32 * line_height),
|
||||||
.x_for_index(block.column() as usize)
|
},
|
||||||
};
|
cx,
|
||||||
|
);
|
||||||
let mut element = block.render(&BlockContext { cx, anchor_x });
|
(start_row, element)
|
||||||
element.layout(
|
})
|
||||||
SizeConstraint {
|
.collect()
|
||||||
min: Vector2F::zero(),
|
|
||||||
max: vec2f(text_width, block.height() as f32 * line_height),
|
|
||||||
},
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
(start_row, element)
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
blocks.extend(
|
|
||||||
snapshot
|
|
||||||
.excerpt_headers_in_range(rows.clone())
|
|
||||||
.map(|(rows, render)| {
|
|
||||||
let mut element = render(cx);
|
|
||||||
element.layout(
|
|
||||||
SizeConstraint {
|
|
||||||
min: Vector2F::zero(),
|
|
||||||
max: vec2f(text_width, rows.len() as f32 * line_height),
|
|
||||||
},
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
(rows.start, element)
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
blocks
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user