Merge pull request #14245 from overleaf/mj-linebreak-arguments

[lezer+visual] Allow optional arguments for line breaks

GitOrigin-RevId: e59a7c9a2efacc8a0fde887736899bbcbb52a4bc
This commit is contained in:
Mathias Jakobsen 2023-08-14 09:16:27 +01:00 committed by Copybot
parent 0b91a2052a
commit 56438c32cc
4 changed files with 18 additions and 12 deletions

View file

@ -66,8 +66,9 @@ function parseColumnSpecifications(specification: string): ColumnDefinition[] {
return columns
}
const isRowSeparator = (node: SyntaxNode, state: EditorState) =>
node.type.is('Command') && state.sliceDoc(node.from, node.to) === '\\\\'
const isRowSeparator = (node: SyntaxNode) =>
node.type.is('Command') &&
Boolean(node.getChild('KnownCtrlSym')?.getChild('LineBreak'))
const isHLine = (node: SyntaxNode) =>
node.type.is('Command') &&
@ -133,7 +134,7 @@ function parseTabularBody(
currentChild;
currentChild = currentChild.nextSibling
) {
if (isRowSeparator(currentChild, state)) {
if (isRowSeparator(currentChild)) {
const lastRow = getLastRow()
body.rows.push({
cells: [],

View file

@ -794,13 +794,17 @@ export const atomicDecorations = (options: Options) => {
}).range(nodeRef.from, nodeRef.to)
)
}
} else if (nodeRef.type.is('LineBreakCtrlSym')) {
} else if (nodeRef.type.is('LineBreak')) {
// line break
const optionalArgument = nodeRef.node.getChild('OptionalArgument')
if (!optionalArgument || shouldDecorate(state, optionalArgument)) {
decorations.push(
Decoration.replace({
widget: new IndicatorWidget('\u21A9'),
}).range(nodeRef.from, nodeRef.to)
)
}
return false
} else if (nodeRef.type.is('Caption')) {
if (shouldDecorate(state, nodeRef)) {
// a caption

View file

@ -1,6 +1,5 @@
import { EditorState } from '@codemirror/state'
import { SyntaxNode } from '@lezer/common'
import { LineBreakCtrlSym } from '../../../lezer-latex/latex.terms.mjs'
const isUnknownCommandWithName = (
node: SyntaxNode,
@ -92,7 +91,7 @@ export function typesetNodeIntoElement(
// ignoring these commands
from = childNode.to
return false
} else if (childNode.type.is(LineBreakCtrlSym)) {
} else if (childNode.type.is('LineBreak')) {
ancestor().appendChild(document.createElement('br'))
from = childNode.to
}

View file

@ -360,7 +360,9 @@ Command {
}
KnownCtrlSym {
LineBreakCtrlSym
LineBreak {
LineBreakCtrlSym OptionalArgument?
}
}
textBase {