mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-26 03:59:55 +00:00
Fix BlockSnapshot::chunks when starting in a block
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
1c3bf90a8a
commit
00b5cc472e
1 changed files with 43 additions and 22 deletions
|
@ -89,7 +89,6 @@ pub struct Chunks<'a> {
|
||||||
block_chunks: Option<BlockChunks<'a>>,
|
block_chunks: Option<BlockChunks<'a>>,
|
||||||
output_row: u32,
|
output_row: u32,
|
||||||
max_output_row: u32,
|
max_output_row: u32,
|
||||||
max_input_row: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlockChunks<'a> {
|
struct BlockChunks<'a> {
|
||||||
|
@ -464,33 +463,41 @@ impl BlockSnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chunks(&self, rows: Range<u32>, highlights: bool) -> Chunks {
|
pub fn chunks(&self, rows: Range<u32>, highlights: bool) -> Chunks {
|
||||||
let max_input_row = self.transforms.summary().input_rows;
|
|
||||||
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
|
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
|
||||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
||||||
let output_row = rows.start;
|
let input_end = {
|
||||||
cursor.seek(&BlockRow(output_row), Bias::Right, &());
|
cursor.seek(&BlockRow(rows.end), Bias::Right, &());
|
||||||
let (input_start, output_start) = cursor.start();
|
let overshoot = if cursor
|
||||||
let overshoot = rows.start - output_start.0;
|
.item()
|
||||||
let output_end_row = max_output_row.saturating_sub(1);
|
.map_or(false, |transform| transform.is_isomorphic())
|
||||||
let input_start_row = input_start.0 + overshoot;
|
{
|
||||||
let input_end_row = self
|
rows.end - cursor.start().0 .0
|
||||||
.to_wrap_point(BlockPoint::new(
|
} else {
|
||||||
output_end_row,
|
0
|
||||||
self.wrap_snapshot.line_len(output_end_row),
|
};
|
||||||
))
|
cursor.start().1 .0 + overshoot
|
||||||
.row()
|
};
|
||||||
+ 1;
|
let input_start = {
|
||||||
let input_chunks = self
|
cursor.seek(&BlockRow(rows.start), Bias::Right, &());
|
||||||
.wrap_snapshot
|
let overshoot = if cursor
|
||||||
.chunks(input_start_row..input_end_row, highlights);
|
.item()
|
||||||
|
.map_or(false, |transform| transform.is_isomorphic())
|
||||||
|
{
|
||||||
|
rows.start - cursor.start().0 .0
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
cursor.start().1 .0 + overshoot
|
||||||
|
};
|
||||||
Chunks {
|
Chunks {
|
||||||
input_chunks,
|
input_chunks: self
|
||||||
|
.wrap_snapshot
|
||||||
|
.chunks(input_start..input_end, highlights),
|
||||||
input_chunk: Default::default(),
|
input_chunk: Default::default(),
|
||||||
block_chunks: None,
|
block_chunks: None,
|
||||||
transforms: cursor,
|
transforms: cursor,
|
||||||
output_row,
|
output_row: rows.start,
|
||||||
max_output_row,
|
max_output_row,
|
||||||
max_input_row,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1253,7 +1260,21 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(blocks_snapshot.text(), expected_text);
|
let expected_lines = expected_text.split('\n').collect::<Vec<_>>();
|
||||||
|
let expected_row_count = expected_lines.len();
|
||||||
|
for start_row in 0..expected_row_count {
|
||||||
|
let expected_text = expected_lines[start_row..].join("\n");
|
||||||
|
let actual_text = blocks_snapshot
|
||||||
|
.chunks(start_row as u32..expected_row_count as u32, false)
|
||||||
|
.map(|chunk| chunk.text)
|
||||||
|
.collect::<String>();
|
||||||
|
assert_eq!(
|
||||||
|
actual_text, expected_text,
|
||||||
|
"incorrect text starting from row {}",
|
||||||
|
start_row
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for row in 0..=blocks_snapshot.wrap_snapshot.max_point().row() {
|
for row in 0..=blocks_snapshot.wrap_snapshot.max_point().row() {
|
||||||
let wrap_point = WrapPoint::new(row, 0);
|
let wrap_point = WrapPoint::new(row, 0);
|
||||||
let block_point = blocks_snapshot.to_block_point(wrap_point);
|
let block_point = blocks_snapshot.to_block_point(wrap_point);
|
||||||
|
|
Loading…
Reference in a new issue