mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 12:32:32 -05:00
6c21f0821c
* Use fork of @codemirror/autocomplete * Handle multiple selection ranges when applying snippets GitOrigin-RevId: 04afc087ac127206463ea3d4950284a50308364a
23 lines
726 B
TypeScript
23 lines
726 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 : []),
|
|
}
|
|
}
|
|
|
|
const extension = [
|
|
closeBrackets(),
|
|
// NOTE: using Prec.highest as this needs to run before the default Backspace handler
|
|
Prec.highest(keymap.of(closeBracketsKeymap)),
|
|
]
|