mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix incremental bugs
Co-Authored-By: Martin Haug <mhaug@live.de>
This commit is contained in:
parent
3cc026cf39
commit
790bd536eb
@ -45,12 +45,14 @@ impl Reparser<'_> {
|
|||||||
) -> Option<Range<usize>> {
|
) -> Option<Range<usize>> {
|
||||||
let child_mode = green.kind().only_in_mode().unwrap_or(TokenMode::Code);
|
let child_mode = green.kind().only_in_mode().unwrap_or(TokenMode::Code);
|
||||||
let original_count = green.children().len();
|
let original_count = green.children().len();
|
||||||
|
let original_offset = offset;
|
||||||
|
|
||||||
let mut search = SearchState::default();
|
let mut search = SearchState::default();
|
||||||
let mut ahead_nontrivia = None;
|
let mut ahead_nontrivia = None;
|
||||||
|
|
||||||
// Whether the first node that should be replaced is at start.
|
// Whether the first node that should be replaced is at start.
|
||||||
let mut at_start = true;
|
let mut at_start = true;
|
||||||
|
|
||||||
// Whether the last searched child is the outermost child.
|
// Whether the last searched child is the outermost child.
|
||||||
let mut child_outermost = false;
|
let mut child_outermost = false;
|
||||||
|
|
||||||
@ -77,8 +79,12 @@ impl Reparser<'_> {
|
|||||||
} else if child_span.contains(&self.replace_range.start) {
|
} else if child_span.contains(&self.replace_range.start) {
|
||||||
search = SearchState::Inside(pos);
|
search = SearchState::Inside(pos);
|
||||||
} else {
|
} else {
|
||||||
if (!child.kind().is_space()
|
// We look only for non spaces, non-semicolon and also
|
||||||
&& child.kind() != &NodeKind::Semicolon)
|
// reject text that points to the special case for URL
|
||||||
|
// evasion and line comments.
|
||||||
|
if !child.kind().is_space()
|
||||||
|
&& child.kind() != &NodeKind::Semicolon
|
||||||
|
&& child.kind() != &NodeKind::Text('/'.into())
|
||||||
&& (ahead_nontrivia.is_none()
|
&& (ahead_nontrivia.is_none()
|
||||||
|| self.replace_range.start > child_span.end)
|
|| self.replace_range.start > child_span.end)
|
||||||
{
|
{
|
||||||
@ -173,6 +179,8 @@ impl Reparser<'_> {
|
|||||||
start = ahead;
|
start = ahead;
|
||||||
at_start = ahead_at_start;
|
at_start = ahead_at_start;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
start = GreenPos { idx: 0, offset: original_offset };
|
||||||
}
|
}
|
||||||
|
|
||||||
let superseded_span =
|
let superseded_span =
|
||||||
@ -350,6 +358,7 @@ mod tests {
|
|||||||
test("#for", 4 .. 4, "//", 0 .. 6);
|
test("#for", 4 .. 4, "//", 0 .. 6);
|
||||||
test("a\n#let \nb", 7 .. 7, "i", 2 .. 9);
|
test("a\n#let \nb", 7 .. 7, "i", 2 .. 9);
|
||||||
test("a\n#for i \nb", 9 .. 9, "in", 2 .. 12);
|
test("a\n#for i \nb", 9 .. 9, "in", 2 .. 12);
|
||||||
|
test("a~https://fun/html", 13..14, "n", 2..18);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -365,6 +374,8 @@ mod tests {
|
|||||||
test("hey #myfriend", 4 .. 4, "\\", 3 .. 6);
|
test("hey #myfriend", 4 .. 4, "\\", 3 .. 6);
|
||||||
test("= foo\nbar\n - a\n - b", 6 .. 9, "", 0 .. 11);
|
test("= foo\nbar\n - a\n - b", 6 .. 9, "", 0 .. 11);
|
||||||
test("= foo\n bar\n baz", 6 .. 8, "", 0 .. 9);
|
test("= foo\n bar\n baz", 6 .. 8, "", 0 .. 9);
|
||||||
|
test(" // hi", 1 .. 1, " ", 0 .. 7);
|
||||||
|
test("- \nA", 2..3, "", 0..3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -282,7 +282,7 @@ fn heading(p: &mut Parser, at_start: bool) {
|
|||||||
marker.end(p, NodeKind::Heading);
|
marker.end(p, NodeKind::Heading);
|
||||||
} else {
|
} else {
|
||||||
let text = p.get(current_start .. p.prev_end()).into();
|
let text = p.get(current_start .. p.prev_end()).into();
|
||||||
marker.convert(p, NodeKind::TextInLine(text));
|
marker.convert(p, NodeKind::Text(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ fn list_node(p: &mut Parser, at_start: bool) {
|
|||||||
markup_indented(p, column);
|
markup_indented(p, column);
|
||||||
marker.end(p, NodeKind::List);
|
marker.end(p, NodeKind::List);
|
||||||
} else {
|
} else {
|
||||||
marker.convert(p, NodeKind::TextInLine(text));
|
marker.convert(p, NodeKind::Text(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ fn enum_node(p: &mut Parser, at_start: bool) {
|
|||||||
markup_indented(p, column);
|
markup_indented(p, column);
|
||||||
marker.end(p, NodeKind::Enum);
|
marker.end(p, NodeKind::Enum);
|
||||||
} else {
|
} else {
|
||||||
marker.convert(p, NodeKind::TextInLine(text));
|
marker.convert(p, NodeKind::Text(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +63,7 @@ impl Markup {
|
|||||||
NodeKind::Space(2 ..) => Some(MarkupNode::Parbreak),
|
NodeKind::Space(2 ..) => Some(MarkupNode::Parbreak),
|
||||||
NodeKind::Space(_) => Some(MarkupNode::Space),
|
NodeKind::Space(_) => Some(MarkupNode::Space),
|
||||||
NodeKind::Linebreak => Some(MarkupNode::Linebreak),
|
NodeKind::Linebreak => Some(MarkupNode::Linebreak),
|
||||||
NodeKind::Text(s) | NodeKind::TextInLine(s) => {
|
NodeKind::Text(s) => Some(MarkupNode::Text(s.clone())),
|
||||||
Some(MarkupNode::Text(s.clone()))
|
|
||||||
}
|
|
||||||
NodeKind::Escape(c) => Some(MarkupNode::Text((*c).into())),
|
NodeKind::Escape(c) => Some(MarkupNode::Text((*c).into())),
|
||||||
NodeKind::NonBreakingSpace => Some(MarkupNode::Text('\u{00A0}'.into())),
|
NodeKind::NonBreakingSpace => Some(MarkupNode::Text('\u{00A0}'.into())),
|
||||||
NodeKind::EnDash => Some(MarkupNode::Text('\u{2013}'.into())),
|
NodeKind::EnDash => Some(MarkupNode::Text('\u{2013}'.into())),
|
||||||
|
@ -195,7 +195,6 @@ impl Category {
|
|||||||
NodeKind::Markup(_) => None,
|
NodeKind::Markup(_) => None,
|
||||||
NodeKind::Space(_) => None,
|
NodeKind::Space(_) => None,
|
||||||
NodeKind::Text(_) => None,
|
NodeKind::Text(_) => None,
|
||||||
NodeKind::TextInLine(_) => None,
|
|
||||||
NodeKind::List => None,
|
NodeKind::List => None,
|
||||||
NodeKind::Enum => None,
|
NodeKind::Enum => None,
|
||||||
NodeKind::CodeBlock => None,
|
NodeKind::CodeBlock => None,
|
||||||
|
@ -590,8 +590,6 @@ pub enum NodeKind {
|
|||||||
Linebreak,
|
Linebreak,
|
||||||
/// A consecutive non-markup string.
|
/// A consecutive non-markup string.
|
||||||
Text(EcoString),
|
Text(EcoString),
|
||||||
/// A text node that cannot appear at the beginning of a source line.
|
|
||||||
TextInLine(EcoString),
|
|
||||||
/// A non-breaking space: `~`.
|
/// A non-breaking space: `~`.
|
||||||
NonBreakingSpace,
|
NonBreakingSpace,
|
||||||
/// An en-dash: `--`.
|
/// An en-dash: `--`.
|
||||||
@ -757,6 +755,7 @@ impl NodeKind {
|
|||||||
pub fn only_at_start(&self) -> bool {
|
pub fn only_at_start(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Heading | Self::Enum | Self::List => true,
|
Self::Heading | Self::Enum | Self::List => true,
|
||||||
|
Self::Text(t) => t == "-" || t.ends_with('.'),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -767,7 +766,6 @@ impl NodeKind {
|
|||||||
Self::Markup(_)
|
Self::Markup(_)
|
||||||
| Self::Linebreak
|
| Self::Linebreak
|
||||||
| Self::Text(_)
|
| Self::Text(_)
|
||||||
| Self::TextInLine(_)
|
|
||||||
| Self::NonBreakingSpace
|
| Self::NonBreakingSpace
|
||||||
| Self::EnDash
|
| Self::EnDash
|
||||||
| Self::EmDash
|
| Self::EmDash
|
||||||
@ -859,7 +857,7 @@ impl NodeKind {
|
|||||||
Self::Space(2 ..) => "paragraph break",
|
Self::Space(2 ..) => "paragraph break",
|
||||||
Self::Space(_) => "space",
|
Self::Space(_) => "space",
|
||||||
Self::Linebreak => "forced linebreak",
|
Self::Linebreak => "forced linebreak",
|
||||||
Self::Text(_) | Self::TextInLine(_) => "text",
|
Self::Text(_) => "text",
|
||||||
Self::NonBreakingSpace => "non-breaking space",
|
Self::NonBreakingSpace => "non-breaking space",
|
||||||
Self::EnDash => "en dash",
|
Self::EnDash => "en dash",
|
||||||
Self::EmDash => "em dash",
|
Self::EmDash => "em dash",
|
||||||
@ -980,7 +978,6 @@ impl Hash for NodeKind {
|
|||||||
Self::Space(n) => n.hash(state),
|
Self::Space(n) => n.hash(state),
|
||||||
Self::Linebreak => {}
|
Self::Linebreak => {}
|
||||||
Self::Text(s) => s.hash(state),
|
Self::Text(s) => s.hash(state),
|
||||||
Self::TextInLine(s) => s.hash(state),
|
|
||||||
Self::NonBreakingSpace => {}
|
Self::NonBreakingSpace => {}
|
||||||
Self::EnDash => {}
|
Self::EnDash => {}
|
||||||
Self::EmDash => {}
|
Self::EmDash => {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user