mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
359255b820
GitOrigin-RevId: a24020ed216cb10defff989f5876666c29889de2
29 lines
801 B
TypeScript
29 lines
801 B
TypeScript
import { keymap } from '@codemirror/view'
|
|
import { Compartment, Prec, TransactionSpec } from '@codemirror/state'
|
|
import { closeBrackets, closeBracketsKeymap } from './close-brackets'
|
|
|
|
const autoPairConf = new Compartment()
|
|
|
|
export const autoPair = ({
|
|
autoPairDelimiters,
|
|
}: {
|
|
autoPairDelimiters: boolean
|
|
}) => autoPairConf.of(createAutoPair(autoPairDelimiters))
|
|
|
|
export const setAutoPair = (autoPairDelimiters: boolean): TransactionSpec => {
|
|
return {
|
|
effects: autoPairConf.reconfigure(createAutoPair(autoPairDelimiters)),
|
|
}
|
|
}
|
|
|
|
const createAutoPair = (enabled: boolean) => {
|
|
if (!enabled) {
|
|
return []
|
|
}
|
|
|
|
return [
|
|
closeBrackets(),
|
|
// NOTE: using Prec.highest as this needs to run before the default Backspace handler
|
|
Prec.highest(keymap.of(closeBracketsKeymap)),
|
|
]
|
|
}
|