From c56a8c41f0106fcf4bfa55a8b679e4f748b96caa Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 1 Jun 2022 10:30:28 +0200 Subject: [PATCH] Fix that incremental reparsing is impossible at the end Co-Authored-By: Martin Haug --- src/parse/incremental.rs | 9 +++++++-- src/parse/mod.rs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/parse/incremental.rs b/src/parse/incremental.rs index e567cb073..3cafc0141 100644 --- a/src/parse/incremental.rs +++ b/src/parse/incremental.rs @@ -68,6 +68,7 @@ impl Reparser<'_> { for (i, child) in node.children().enumerate() { let pos = NodePos { idx: i, offset }; let child_span = offset .. offset + child.len(); + child_outermost = outermost && i + 1 == original_count; match search { SearchState::NoneFound => { @@ -84,6 +85,11 @@ impl Reparser<'_> { }; } else if child_span.contains(&self.replaced.start) { search = SearchState::Inside(pos); + } else if child_span.end == self.replaced.start + && self.replaced.start == self.replaced.end + && child_outermost + { + search = SearchState::SpanFound(pos, pos); } else { // We look only for non spaces, non-semicolon and also // reject text that points to the special case for URL @@ -115,7 +121,6 @@ impl Reparser<'_> { } offset += child.len(); - child_outermost = outermost && i + 1 == original_count; if search.done().is_some() { break; @@ -346,7 +351,7 @@ mod tests { test("a\nb\nc *hel a b lo* d\nd\ne", 13..13, "c ", 6..20); test("~~ {a} ~~", 4 .. 5, "b", 3 .. 6); test("{(0, 1, 2)}", 5 .. 6, "11pt", 0..14); - test("\n= A heading", 3 .. 3, "n evocative", 3 .. 23); + test("\n= A heading", 4 .. 4, "n evocative", 3 .. 23); test("for~your~thing", 9 .. 9, "a", 4 .. 15); test("a your thing a", 6 .. 7, "a", 0 .. 14); test("{call(); abc}", 7 .. 7, "[]", 0 .. 15); diff --git a/src/parse/mod.rs b/src/parse/mod.rs index fddef04c1..be3af1f8c 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -107,7 +107,7 @@ fn reparse_markup_elements( markup_node(&mut p, &mut at_start); - if p.prev_end() < end_pos { + if p.prev_end() <= end_pos { continue; }