Make BlockMap
randomized test pass in low-complexity cases
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
296944e34d
commit
cebab56c94
2 changed files with 19 additions and 29 deletions
|
@ -94,16 +94,6 @@ impl Rope {
|
||||||
self.append(suffix);
|
self.append(suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn starts_with(&self, text: &str) -> bool {
|
|
||||||
self.chunks().flat_map(|c| c.bytes()).eq(text.bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ends_with(&self, text: &str) -> bool {
|
|
||||||
self.reversed_chunks_in_range(0..self.len())
|
|
||||||
.flat_map(|c| c.bytes().rev())
|
|
||||||
.eq(text.bytes().rev())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_invariants(&self) {
|
fn check_invariants(&self) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
{
|
{
|
||||||
|
|
|
@ -189,13 +189,16 @@ impl BlockMap {
|
||||||
|
|
||||||
dbg!("expanded edit", &edit);
|
dbg!("expanded edit", &edit);
|
||||||
let start_anchor = buffer.anchor_before(Point::new(edit.new.start, 0));
|
let start_anchor = buffer.anchor_before(Point::new(edit.new.start, 0));
|
||||||
let end_anchor = buffer.anchor_before(Point::new(edit.new.end, 0));
|
|
||||||
let start_block_ix = match self.blocks[last_block_ix..]
|
let start_block_ix = match self.blocks[last_block_ix..]
|
||||||
.binary_search_by(|probe| probe.position.cmp(&start_anchor, buffer).unwrap())
|
.binary_search_by(|probe| probe.position.cmp(&start_anchor, buffer).unwrap())
|
||||||
{
|
{
|
||||||
Ok(ix) | Err(ix) => last_block_ix + ix,
|
Ok(ix) | Err(ix) => last_block_ix + ix,
|
||||||
};
|
};
|
||||||
let end_block_ix = match self.blocks[start_block_ix..].binary_search_by(|probe| {
|
let end_block_ix = if edit.new.end > wrap_snapshot.max_point().row() {
|
||||||
|
self.blocks.len()
|
||||||
|
} else {
|
||||||
|
let end_anchor = buffer.anchor_before(Point::new(edit.new.end, 0));
|
||||||
|
match self.blocks[start_block_ix..].binary_search_by(|probe| {
|
||||||
probe
|
probe
|
||||||
.position
|
.position
|
||||||
.cmp(&end_anchor, buffer)
|
.cmp(&end_anchor, buffer)
|
||||||
|
@ -203,6 +206,7 @@ impl BlockMap {
|
||||||
.then(Ordering::Greater)
|
.then(Ordering::Greater)
|
||||||
}) {
|
}) {
|
||||||
Ok(ix) | Err(ix) => start_block_ix + ix,
|
Ok(ix) | Err(ix) => start_block_ix + ix,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
last_block_ix = end_block_ix;
|
last_block_ix = end_block_ix;
|
||||||
|
|
||||||
|
@ -240,10 +244,9 @@ impl BlockMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_transforms_end = new_transforms.summary().input;
|
let new_transforms_end = new_transforms.summary().input;
|
||||||
if new_transforms_end.row < edit.new.end - 1 {
|
|
||||||
// TODO: Should we just report the wrap edits in 2d so we can skip this max point check?
|
|
||||||
let edit_new_end_point =
|
let edit_new_end_point =
|
||||||
cmp::min(Point::new(edit.new.end, 0), wrap_snapshot.max_point().0);
|
cmp::min(Point::new(edit.new.end, 0), wrap_snapshot.max_point().0);
|
||||||
|
if new_transforms_end < edit_new_end_point {
|
||||||
new_transforms.push(
|
new_transforms.push(
|
||||||
Transform::isomorphic(edit_new_end_point - new_transforms_end),
|
Transform::isomorphic(edit_new_end_point - new_transforms_end),
|
||||||
&(),
|
&(),
|
||||||
|
@ -306,14 +309,10 @@ impl<'a> BlockMapWriter<'a> {
|
||||||
};
|
};
|
||||||
let mut text = block.text.into();
|
let mut text = block.text.into();
|
||||||
if block.disposition.is_above() {
|
if block.disposition.is_above() {
|
||||||
if !text.ends_with("\n") {
|
|
||||||
text.push("\n");
|
text.push("\n");
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if !text.starts_with("\n") {
|
|
||||||
text.push_front("\n");
|
text.push_front("\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.0.blocks.insert(
|
self.0.blocks.insert(
|
||||||
block_ix,
|
block_ix,
|
||||||
|
@ -745,6 +744,7 @@ mod tests {
|
||||||
let buffer = cx.add_model(|cx| {
|
let buffer = cx.add_model(|cx| {
|
||||||
let len = rng.gen_range(0..10);
|
let len = rng.gen_range(0..10);
|
||||||
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
|
||||||
|
log::info!("initial buffer text: {:?}", text);
|
||||||
Buffer::new(0, text, cx)
|
Buffer::new(0, text, cx)
|
||||||
});
|
});
|
||||||
let (fold_map, folds_snapshot) = FoldMap::new(buffer.clone(), cx);
|
let (fold_map, folds_snapshot) = FoldMap::new(buffer.clone(), cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue