mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
e025088065
Add documentation for CodeMirror extensions GitOrigin-RevId: e5f07084173f201919272f9d46dcdaef4b817874
26 lines
800 B
TypeScript
26 lines
800 B
TypeScript
import { keymap } from '@codemirror/view'
|
|
import { Compartment, Prec, TransactionSpec } from '@codemirror/state'
|
|
import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete'
|
|
|
|
const autoPairConf = new Compartment()
|
|
|
|
export const autoPair = ({
|
|
autoPairDelimiters,
|
|
}: {
|
|
autoPairDelimiters: boolean
|
|
}) => autoPairConf.of(autoPairDelimiters ? extension : [])
|
|
|
|
export const setAutoPair = (autoPairDelimiters: boolean): TransactionSpec => {
|
|
return {
|
|
effects: autoPairConf.reconfigure(autoPairDelimiters ? extension : []),
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The built-in closeBrackets extension and closeBrackets keymap.
|
|
*/
|
|
const extension = [
|
|
closeBrackets(),
|
|
// NOTE: using Prec.highest as this needs to run before the default Backspace handler
|
|
Prec.highest(keymap.of(closeBracketsKeymap)),
|
|
]
|