mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-07 10:49:47 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2763610d65 |
+2
-1
File diff suppressed because one or more lines are too long
@@ -74,8 +74,9 @@ pub fn anchors(doc: &Document) -> Vec<(u32, Pos)> {
|
||||
let mut out = Vec::new();
|
||||
for path in doc.para_paths(StoryRef::Body) {
|
||||
let Some(p) = doc.para(StoryRef::Body, &path) else { continue };
|
||||
for off in p.object_offsets() {
|
||||
let Some(InlineObject::CommentStart { id }) = p.object_at(off) else { continue };
|
||||
// One pass over the objects: `object_at` per offset counted the objects before each one.
|
||||
for (off, obj) in p.objects_with_offsets() {
|
||||
let InlineObject::CommentStart { id } = obj else { continue };
|
||||
if !doc.comments.contains_key(id) || root(doc, *id) != *id || !seen.insert(*id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -294,3 +294,20 @@ fn a_kept_outline_holds_on_to_its_pictures_allocation() {
|
||||
drop(disc);
|
||||
assert!(weak.upgrade().is_none(), "the bytes are freed with the document; only their allocation is kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_anchors_are_found_in_one_pass_over_a_paragraph() {
|
||||
// 20,000 comment ends before the one start: each marker counted the objects before it again.
|
||||
let n = 20_000usize;
|
||||
let mut d = Document::from_text("");
|
||||
d.comments.insert(1, wordcraft_doc::Comment::default());
|
||||
if let Some(Block::Para(p)) = d.body.first_mut().map(Arc::make_mut) {
|
||||
p.text = wordcraft_doc::para::OBJ.to_string().repeat(n + 1);
|
||||
p.runs = vec![wordcraft_doc::para::Run { len: p.text.len(), props: Default::default() }];
|
||||
p.objects = (0..n).map(|_| InlineObject::CommentEnd { id: 1 }).collect();
|
||||
p.objects.push(InlineObject::CommentStart { id: 1 });
|
||||
}
|
||||
let found = balloons::anchors(&d);
|
||||
assert_eq!(found.len(), 1);
|
||||
assert_eq!(found[0].1.off, n * wordcraft_doc::para::OBJ.len_utf8());
|
||||
}
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user