Extract completion function

This commit is contained in:
Adria Navarro 2025-02-10 11:14:17 +01:00
parent 973f6e6ae8
commit d09288542b
1 changed files with 31 additions and 26 deletions

View File

@ -244,26 +244,12 @@
] ]
} }
// None of this is reactive, but it never has been, so we just assume most function handleCompletions(
// config flags aren't changed at runtime view: EditorView,
// TODO: work out type for base from: number,
const buildExtensions = (base: any[]) => { to: number,
let complete = [...base] insert: string
) {
if (autocompleteEnabled) {
complete.push(
autocompletion({
override: [...completions],
closeOnBlur: true,
icons: false,
optionClass: completion =>
"simple" in completion && completion.simple
? "autocomplete-option-simple"
: "autocomplete-option",
})
)
complete.push(
EditorView.inputHandler.of((view, from, to, insert) => {
if (jsBindingWrapping && insert === "$") { if (jsBindingWrapping && insert === "$") {
let { text } = view.state.doc.lineAt(from) let { text } = view.state.doc.lineAt(from)
@ -286,8 +272,27 @@
return true return true
} }
return false return false
}
// None of this is reactive, but it never has been, so we just assume most
// config flags aren't changed at runtime
// TODO: work out type for base
const buildExtensions = (base: any[]) => {
let complete = [...base]
if (autocompleteEnabled) {
complete.push(
autocompletion({
override: [...completions],
closeOnBlur: true,
icons: false,
optionClass: completion =>
"simple" in completion && completion.simple
? "autocomplete-option-simple"
: "autocomplete-option",
}) })
) )
complete.push(EditorView.inputHandler.of(handleCompletions))
} }
// JS only plugins // JS only plugins