mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-22 23:56:23 +00:00
[cm6] fix toggling ranges next to command (#14183)
GitOrigin-RevId: 4959419a09415b202dc7ce2271e9691d2c2387d4
This commit is contained in:
parent
b126d1f8f6
commit
f37ae7a5f8
2 changed files with 33 additions and 1 deletions
|
@ -467,7 +467,15 @@ export function toggleRanges(
|
|||
range.to === view.state.doc.length ? -1 : 1
|
||||
)
|
||||
|
||||
if (ancestorAtStartOfRange !== ancestorAtEndOfRange) {
|
||||
const tree = ensureSyntaxTree(view.state, 1000)
|
||||
const nodeAtFrom = tree?.resolveInner(range.from, 1)
|
||||
const nodeAtTo = tree?.resolveInner(range.to, -1)
|
||||
const isSingleNodeSelected = nodeAtFrom === nodeAtTo
|
||||
|
||||
if (
|
||||
!isSingleNodeSelected &&
|
||||
ancestorAtStartOfRange !== ancestorAtEndOfRange
|
||||
) {
|
||||
// But handle the exception of case 8
|
||||
const ancestorAtStartIsWrappingCommand =
|
||||
ancestorAtStartOfRange &&
|
||||
|
|
|
@ -196,4 +196,28 @@ describe('toggleRanges', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('still formats text next to a command', function () {
|
||||
const cm = new CodemirrorTestSession(['<item>\\foo'])
|
||||
cm.applyCommand(BOLD_COMMAND)
|
||||
expect(cm).line(1).to.equal('\\textbf{item}\\foo')
|
||||
})
|
||||
|
||||
it('still formats part of a text next to command', function () {
|
||||
const cm = new CodemirrorTestSession(['hello <world>\\foo'])
|
||||
cm.applyCommand(BOLD_COMMAND)
|
||||
expect(cm).line(1).to.equal('hello \\textbf{world}\\foo')
|
||||
})
|
||||
|
||||
it('still formats command without arguments', function () {
|
||||
const cm = new CodemirrorTestSession(['\\item<\\foo>'])
|
||||
cm.applyCommand(BOLD_COMMAND)
|
||||
expect(cm).line(1).to.equal('\\item\\textbf{<\\foo>}')
|
||||
})
|
||||
|
||||
it('skips formatting if in the middle of two commands', function () {
|
||||
const cm = new CodemirrorTestSession(['\\f<oo\\b>ar'])
|
||||
cm.applyCommand(BOLD_COMMAND)
|
||||
expect(cm).line(1).to.equal('\\foo\\bar')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue