Merge pull request #13607 from overleaf/ae-formatting-keymaps

[cm6] Use toggleRanges for bold/italic shortcuts in code editor

GitOrigin-RevId: 90f7344876e84b984469ca2daccb7bbe71d89aa9
This commit is contained in:
Alf Eaton 2023-07-04 09:12:27 +01:00 committed by Copybot
parent bd770e8a8c
commit a716a500c5
3 changed files with 4 additions and 20 deletions

View file

@ -268,9 +268,7 @@ function moveRange(range: SelectionRange, newFrom: number, newTo: number) {
function validateReplacement(expected: string, actual: string) {
if (expected !== actual) {
throw new Error(
`Replacement in toggleRange failed validation. Expected ${expected} got ${actual}`
)
throw new Error('Replacement in toggleRange failed validation.')
}
}

View file

@ -1,7 +1,6 @@
import { keymap } from '@codemirror/view'
import { EditorSelection, Prec } from '@codemirror/state'
import { ancestorNodeOfType } from '../../utils/tree-query'
import { toggleRanges } from '../../commands/ranges'
import {
getIndentation,
IndentContext,
@ -128,18 +127,5 @@ export const visualKeymap = Prec.highest(
preventDefault: true,
run: indentDecrease,
},
// Override bolding in RT mode
{
key: 'Ctrl-b',
mac: 'Mod-b',
preventDefault: true,
run: toggleRanges('\\textbf'),
},
{
key: 'Ctrl-i',
mac: 'Mod-i',
preventDefault: true,
run: toggleRanges('\\textit'),
},
])
)

View file

@ -1,6 +1,6 @@
import { Prec } from '@codemirror/state'
import { keymap } from '@codemirror/view'
import { wrapRanges } from '../../commands/ranges'
import { toggleRanges } from '../../commands/ranges'
export const shortcuts = () => {
return Prec.high(
@ -9,13 +9,13 @@ export const shortcuts = () => {
key: 'Ctrl-b',
mac: 'Mod-b',
preventDefault: true,
run: wrapRanges('\\textbf{', '}'),
run: toggleRanges('\\textbf'),
},
{
key: 'Ctrl-i',
mac: 'Mod-i',
preventDefault: true,
run: wrapRanges('\\textit{', '}'),
run: toggleRanges('\\textit'),
},
])
)