WIP
This commit is contained in:
parent
e644c0876e
commit
3154ccbafe
1 changed files with 13 additions and 15 deletions
|
@ -81,7 +81,7 @@ pub struct HighlightedChunks<'a> {
|
||||||
input_chunks: wrap_map::HighlightedChunks<'a>,
|
input_chunks: wrap_map::HighlightedChunks<'a>,
|
||||||
input_chunk: HighlightedChunk<'a>,
|
input_chunk: HighlightedChunk<'a>,
|
||||||
block_chunks: Option<BlockChunks<'a>>,
|
block_chunks: Option<BlockChunks<'a>>,
|
||||||
output_row: u32,
|
output_position: Point,
|
||||||
max_output_row: u32,
|
max_output_row: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ impl BlockMap {
|
||||||
next_block_id: AtomicUsize::new(0),
|
next_block_id: AtomicUsize::new(0),
|
||||||
blocks: Vec::new(),
|
blocks: Vec::new(),
|
||||||
transforms: Mutex::new(SumTree::from_item(
|
transforms: Mutex::new(SumTree::from_item(
|
||||||
Transform::isomorphic(wrap_snapshot.text_summary()),
|
Transform::isomorphic(wrap_snapshot.text_summary().lines),
|
||||||
&(),
|
&(),
|
||||||
)),
|
)),
|
||||||
wrap_snapshot: Mutex::new(wrap_snapshot),
|
wrap_snapshot: Mutex::new(wrap_snapshot),
|
||||||
|
@ -292,14 +292,12 @@ impl<'a> BlockMapWriter<'a> {
|
||||||
{
|
{
|
||||||
Ok(ix) | Err(ix) => ix,
|
Ok(ix) | Err(ix) => ix,
|
||||||
};
|
};
|
||||||
let mut text = block.text.into();
|
|
||||||
text.push("\n");
|
|
||||||
self.0.blocks.insert(
|
self.0.blocks.insert(
|
||||||
block_ix,
|
block_ix,
|
||||||
Arc::new(Block {
|
Arc::new(Block {
|
||||||
id,
|
id,
|
||||||
position,
|
position,
|
||||||
text,
|
text: block.text.into(),
|
||||||
runs: block.runs,
|
runs: block.runs,
|
||||||
disposition: block.disposition,
|
disposition: block.disposition,
|
||||||
}),
|
}),
|
||||||
|
@ -348,7 +346,7 @@ impl BlockSnapshot {
|
||||||
input_chunk: Default::default(),
|
input_chunk: Default::default(),
|
||||||
block_chunks: None,
|
block_chunks: None,
|
||||||
transforms: cursor,
|
transforms: cursor,
|
||||||
output_row: rows.start,
|
output_position: rows.start,
|
||||||
max_output_row: rows.end,
|
max_output_row: rows.end,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,13 +447,13 @@ impl<'a> Iterator for HighlightedChunks<'a> {
|
||||||
type Item = HighlightedChunk<'a>;
|
type Item = HighlightedChunk<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.output_row >= self.max_output_row {
|
if self.output_position >= self.max_output_row {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(block_chunks) = self.block_chunks.as_mut() {
|
if let Some(block_chunks) = self.block_chunks.as_mut() {
|
||||||
if let Some(block_chunk) = block_chunks.next() {
|
if let Some(block_chunk) = block_chunks.next() {
|
||||||
self.output_row += block_chunk.text.matches('\n').count() as u32;
|
self.output_position += block_chunk.text.matches('\n').count() as u32;
|
||||||
return Some(block_chunk);
|
return Some(block_chunk);
|
||||||
} else {
|
} else {
|
||||||
self.block_chunks.take();
|
self.block_chunks.take();
|
||||||
|
@ -466,12 +464,12 @@ impl<'a> Iterator for HighlightedChunks<'a> {
|
||||||
if let Some(block) = transform.block.as_ref() {
|
if let Some(block) = transform.block.as_ref() {
|
||||||
let block_start = self.transforms.start().0 .0;
|
let block_start = self.transforms.start().0 .0;
|
||||||
let block_end = self.transforms.end(&()).0 .0;
|
let block_end = self.transforms.end(&()).0 .0;
|
||||||
let start_row_in_block = self.output_row - block_start;
|
let start_row_in_block = self.output_position - block_start;
|
||||||
let end_row_in_block = cmp::min(self.max_output_row, block_end) - block_start;
|
let end_row_in_block = cmp::min(self.max_output_row, block_end) - block_start;
|
||||||
self.transforms.next(&());
|
self.transforms.next(&());
|
||||||
let mut block_chunks = BlockChunks::new(block, start_row_in_block..end_row_in_block);
|
let mut block_chunks = BlockChunks::new(block, start_row_in_block..end_row_in_block);
|
||||||
if let Some(block_chunk) = block_chunks.next() {
|
if let Some(block_chunk) = block_chunks.next() {
|
||||||
self.output_row += block_chunk.text.matches('\n').count() as u32;
|
self.output_position += block_chunk.text.matches('\n').count() as u32;
|
||||||
return Some(block_chunk);
|
return Some(block_chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,9 +478,9 @@ impl<'a> Iterator for HighlightedChunks<'a> {
|
||||||
if let Some(input_chunk) = self.input_chunks.next() {
|
if let Some(input_chunk) = self.input_chunks.next() {
|
||||||
self.input_chunk = input_chunk;
|
self.input_chunk = input_chunk;
|
||||||
} else {
|
} else {
|
||||||
self.output_row += 1;
|
self.output_position += 1;
|
||||||
self.transforms.next(&());
|
self.transforms.next(&());
|
||||||
if self.output_row < self.max_output_row {
|
if self.output_position < self.max_output_row {
|
||||||
let mut chunk = self.input_chunk.clone();
|
let mut chunk = self.input_chunk.clone();
|
||||||
chunk.text = "\n";
|
chunk.text = "\n";
|
||||||
return Some(chunk);
|
return Some(chunk);
|
||||||
|
@ -494,11 +492,11 @@ impl<'a> Iterator for HighlightedChunks<'a> {
|
||||||
|
|
||||||
let transform_end = self.transforms.end(&()).0 .0;
|
let transform_end = self.transforms.end(&()).0 .0;
|
||||||
let (prefix_rows, prefix_bytes) =
|
let (prefix_rows, prefix_bytes) =
|
||||||
offset_for_row(self.input_chunk.text, transform_end - self.output_row);
|
offset_for_row(self.input_chunk.text, transform_end - self.output_position);
|
||||||
self.output_row += prefix_rows;
|
self.output_position += prefix_rows;
|
||||||
let (prefix, suffix) = self.input_chunk.text.split_at(prefix_bytes);
|
let (prefix, suffix) = self.input_chunk.text.split_at(prefix_bytes);
|
||||||
self.input_chunk.text = suffix;
|
self.input_chunk.text = suffix;
|
||||||
if self.output_row == transform_end {
|
if self.output_position == transform_end {
|
||||||
self.transforms.next(&());
|
self.transforms.next(&());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue