mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 04:41:32 +02:00
* Update Copybara options in preparation for open-sourcing the source editor * Move files * Update paths * Remove source-editor module and checks for its existence * Explicitly mention CM6 license in files that contain code adapted from CM6 GitOrigin-RevId: 89b7cc2b409db01ad103198ccbd1b126ab56349b
32 lines
904 B
TypeScript
32 lines
904 B
TypeScript
import { keymap } from '@codemirror/view'
|
|
import { Compartment, Prec, TransactionSpec } from '@codemirror/state'
|
|
import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete'
|
|
import { closePrefixedBrackets } from './close-prefixed-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 [
|
|
closePrefixedBrackets(),
|
|
closeBrackets(),
|
|
// NOTE: using Prec.highest as this needs to run before the default Backspace handler
|
|
Prec.highest(keymap.of(closeBracketsKeymap)),
|
|
]
|
|
}
|