mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Simplify only_in_mode
to only_in_markup
This commit is contained in:
parent
a5a6c2d83f
commit
fcce3df093
@ -4,8 +4,7 @@ use std::sync::Arc;
|
|||||||
use crate::syntax::{Green, GreenNode, NodeKind};
|
use crate::syntax::{Green, GreenNode, NodeKind};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
is_newline, parse, reparse_code_block, reparse_content_block,
|
is_newline, parse, reparse_code_block, reparse_content_block, reparse_markup_elements,
|
||||||
reparse_markup_elements, TokenMode,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Refresh the given green node with as little parsing as possible.
|
/// Refresh the given green node with as little parsing as possible.
|
||||||
@ -49,7 +48,7 @@ impl Reparser<'_> {
|
|||||||
mut offset: usize,
|
mut offset: usize,
|
||||||
outermost: bool,
|
outermost: bool,
|
||||||
) -> Option<Range<usize>> {
|
) -> Option<Range<usize>> {
|
||||||
let child_mode = green.kind().only_in_mode().unwrap_or(TokenMode::Code);
|
let is_markup = matches!(green.kind(), NodeKind::Markup(_));
|
||||||
let original_count = green.children().len();
|
let original_count = green.children().len();
|
||||||
let original_offset = offset;
|
let original_offset = offset;
|
||||||
|
|
||||||
@ -75,9 +74,7 @@ impl Reparser<'_> {
|
|||||||
{
|
{
|
||||||
// In Markup mode, we want to consider a non-whitespace
|
// In Markup mode, we want to consider a non-whitespace
|
||||||
// neighbor if the edit is on the node boundary.
|
// neighbor if the edit is on the node boundary.
|
||||||
search = if child_span.end == self.replaced.end
|
search = if is_markup && child_span.end == self.replaced.end {
|
||||||
&& child_mode == TokenMode::Markup
|
|
||||||
{
|
|
||||||
SearchState::RequireNonTrivia(pos)
|
SearchState::RequireNonTrivia(pos)
|
||||||
} else {
|
} else {
|
||||||
SearchState::Contained(pos)
|
SearchState::Contained(pos)
|
||||||
@ -180,7 +177,7 @@ impl Reparser<'_> {
|
|||||||
|
|
||||||
if start.offset == self.replaced.start
|
if start.offset == self.replaced.start
|
||||||
|| ahead_kind.only_at_start()
|
|| ahead_kind.only_at_start()
|
||||||
|| ahead_kind.only_in_mode() != Some(TokenMode::Markup)
|
|| !ahead_kind.only_in_markup()
|
||||||
{
|
{
|
||||||
start = ahead;
|
start = ahead;
|
||||||
at_start = ahead_at_start;
|
at_start = ahead_at_start;
|
||||||
|
@ -14,7 +14,6 @@ pub use span::*;
|
|||||||
|
|
||||||
use self::ast::{MathNode, RawNode, TypedNode, Unit};
|
use self::ast::{MathNode, RawNode, TypedNode, Unit};
|
||||||
use crate::diag::Error;
|
use crate::diag::Error;
|
||||||
use crate::parse::TokenMode;
|
|
||||||
use crate::source::SourceId;
|
use crate::source::SourceId;
|
||||||
use crate::util::EcoString;
|
use crate::util::EcoString;
|
||||||
|
|
||||||
@ -809,13 +808,14 @@ impl NodeKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Which mode this node can appear in, in both if `None`.
|
/// Whether this is a node that only appears in markup.
|
||||||
pub fn only_in_mode(&self) -> Option<TokenMode> {
|
pub fn only_in_markup(&self) -> bool {
|
||||||
match self {
|
matches!(
|
||||||
Self::Markup(_)
|
self,
|
||||||
|
Self::Text(_)
|
||||||
| Self::Linebreak { .. }
|
| Self::Linebreak { .. }
|
||||||
| Self::Text(_)
|
|
||||||
| Self::NonBreakingSpace
|
| Self::NonBreakingSpace
|
||||||
|
| Self::Shy
|
||||||
| Self::EnDash
|
| Self::EnDash
|
||||||
| Self::EmDash
|
| Self::EmDash
|
||||||
| Self::Ellipsis
|
| Self::Ellipsis
|
||||||
@ -823,33 +823,13 @@ impl NodeKind {
|
|||||||
| Self::Escape(_)
|
| Self::Escape(_)
|
||||||
| Self::Strong
|
| Self::Strong
|
||||||
| Self::Emph
|
| Self::Emph
|
||||||
|
| Self::Raw(_)
|
||||||
|
| Self::Math(_)
|
||||||
| Self::Heading
|
| Self::Heading
|
||||||
|
| Self::List
|
||||||
| Self::Enum
|
| Self::Enum
|
||||||
| Self::EnumNumbering(_)
|
| Self::EnumNumbering(_)
|
||||||
| Self::List
|
)
|
||||||
| Self::Raw(_)
|
|
||||||
| Self::Math(_) => Some(TokenMode::Markup),
|
|
||||||
Self::ContentBlock
|
|
||||||
| Self::Space(_)
|
|
||||||
| Self::Ident(_)
|
|
||||||
| Self::CodeBlock
|
|
||||||
| Self::LetExpr
|
|
||||||
| Self::SetExpr
|
|
||||||
| Self::ShowExpr
|
|
||||||
| Self::WrapExpr
|
|
||||||
| Self::IfExpr
|
|
||||||
| Self::WhileExpr
|
|
||||||
| Self::ForExpr
|
|
||||||
| Self::ImportExpr
|
|
||||||
| Self::FuncCall
|
|
||||||
| Self::IncludeExpr
|
|
||||||
| Self::LineComment
|
|
||||||
| Self::BlockComment
|
|
||||||
| Self::Error(_, _)
|
|
||||||
| Self::Minus
|
|
||||||
| Self::Eq => None,
|
|
||||||
_ => Some(TokenMode::Code),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A human-readable name for the kind.
|
/// A human-readable name for the kind.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user