Add footnote and endnote commands to the LaTeX grammar (#24939)

GitOrigin-RevId: f0342156fa22a1bcf73ae2e8afdcc6f330ba5d37
This commit is contained in:
Alf Eaton
2025-04-28 08:05:33 +00:00
committed by Copybot
parent a9780ccf96
commit c378f0961c
3 changed files with 51 additions and 38 deletions
@@ -1066,6 +1066,44 @@ export const atomicDecorations = (options: Options) => {
)
)
}
} else if (
nodeRef.type.is('FootnoteCommand') ||
nodeRef.type.is('EndnoteCommand')
) {
const textArgumentNode = nodeRef.node.getChild('TextArgument')
if (textArgumentNode) {
if (
state.readOnly &&
selectionIntersects(state.selection, nodeRef)
) {
// a special case for a read-only document:
// always display the content, styled differently from the main content.
decorations.push(
...decorateArgumentBraces(
new BraceWidget(),
textArgumentNode,
nodeRef.from
),
Decoration.mark({
class: 'ol-cm-footnote ol-cm-footnote-view',
}).range(textArgumentNode.from, textArgumentNode.to)
)
} else {
if (shouldDecorate(state, nodeRef)) {
// collapse the footnote when the selection is outside it
decorations.push(
Decoration.replace({
widget: new FootnoteWidget(
nodeRef.type.is('FootnoteCommand')
? 'footnote'
: 'endnote'
),
}).range(nodeRef.from, nodeRef.to)
)
return false
}
}
}
} else if (nodeRef.type.is('UnknownCommand')) {
// a command that's not defined separately by the grammar
const commandNode = nodeRef.node
@@ -1091,43 +1129,6 @@ export const atomicDecorations = (options: Options) => {
)
return false
}
} else if (
commandName === '\\footnote' ||
commandName === '\\endnote'
) {
if (textArgumentNode) {
if (
state.readOnly &&
selectionIntersects(state.selection, nodeRef)
) {
// a special case for a read-only document:
// always display the content, styled differently from the main content.
decorations.push(
...decorateArgumentBraces(
new BraceWidget(),
textArgumentNode,
nodeRef.from
),
Decoration.mark({
class: 'ol-cm-footnote ol-cm-footnote-view',
}).range(textArgumentNode.from, textArgumentNode.to)
)
} else {
if (shouldDecorate(state, nodeRef)) {
// collapse the footnote when the selection is outside it
decorations.push(
Decoration.replace({
widget: new FootnoteWidget(
commandName === '\\footnote'
? 'footnote'
: 'endnote'
),
}).range(nodeRef.from, nodeRef.to)
)
return false
}
}
}
} else if (commandName === '\\LaTeX') {
if (shouldDecorate(state, nodeRef)) {
decorations.push(