mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Avoid auto-closing $ directly before a TeX command (#15039)
GitOrigin-RevId: e620d6b5c82e179c294930801a95fc4c2c77db57
This commit is contained in:
parent
dd19a014c2
commit
04a4450341
2 changed files with 38 additions and 2 deletions
|
@ -1,5 +1,14 @@
|
|||
import { EditorState, SelectionRange, Text } from '@codemirror/state'
|
||||
import { CloseBracketConfig, prevChar } from '@codemirror/autocomplete'
|
||||
import {
|
||||
CharCategory,
|
||||
EditorState,
|
||||
SelectionRange,
|
||||
Text,
|
||||
} from '@codemirror/state'
|
||||
import {
|
||||
CloseBracketConfig,
|
||||
nextChar,
|
||||
prevChar,
|
||||
} from '@codemirror/autocomplete'
|
||||
|
||||
export const closeBracketConfig: CloseBracketConfig = {
|
||||
brackets: ['$', '$$', '[', '{', '('],
|
||||
|
@ -22,6 +31,21 @@ export const closeBracketConfig: CloseBracketConfig = {
|
|||
// don't auto-close \$
|
||||
return open
|
||||
}
|
||||
|
||||
const next = nextChar(state.doc, range.head)
|
||||
if (next === '\\') {
|
||||
// avoid auto-closing $ before a TeX command
|
||||
const pos = range.head + prev.length
|
||||
const postnext = nextChar(state.doc, pos)
|
||||
|
||||
if (state.charCategorizer(pos)(postnext) !== CharCategory.Word) {
|
||||
return open + '$'
|
||||
}
|
||||
|
||||
// don't auto-close $\command
|
||||
return open
|
||||
}
|
||||
|
||||
// avoid creating an odd number of dollar signs
|
||||
const count = countSurroundingCharacters(state.doc, range.from, open)
|
||||
if (count % 2 !== 0) {
|
||||
|
|
|
@ -138,6 +138,18 @@ describe('close brackets', { scrollBehavior: false }, function () {
|
|||
cy.get('@active-line').should('have.text', '2$')
|
||||
})
|
||||
|
||||
it('does not auto-close a dollar sign before a command', function () {
|
||||
cy.get('@active-line').type('\\nu')
|
||||
cy.get('@active-line').type('{leftArrow}{leftArrow}{leftArrow}$')
|
||||
cy.get('@active-line').should('have.text', '$\\nu')
|
||||
})
|
||||
|
||||
it('does auto-close a dollar sign before a newline', function () {
|
||||
cy.get('@active-line').type('\\\\')
|
||||
cy.get('@active-line').type('{leftArrow}{leftArrow}$')
|
||||
cy.get('@active-line').should('have.text', '$$\\\\')
|
||||
})
|
||||
|
||||
it('does auto-close a curly bracket before punctuation', function () {
|
||||
cy.get('@active-line').type(':2')
|
||||
cy.get('@active-line').type('{leftArrow}{leftArrow}{{}')
|
||||
|
|
Loading…
Reference in a new issue