Hello!
I would like to modify the default autocomplete to bring up completions by ‘Ctrl+Space’. According to docs, it should be as simple as setting ‘activateOnTyping:false’ config. While it disables the activation on typing, the assigned keyboard shortcut does not activate the autocomplete.
Simplified snipped based on code example from docs:
import {basicSetup, EditorView} from "codemirror"
import {
defaultKeymap
} from '@codemirror/commands';
import {autocompletion, completionKeymap} from "@codemirror/autocomplete"
import {
keymap
} from '@codemirror/view';
// Our list of completions (can be static, since the editor
/// will do filtering based on context).
const completions = [
{label: "panic", type: "keyword"},
{label: "park", type: "constant", info: "Test completion"},
{label: "password", type: "variable"},
]
function myCompletions(context) {
let before = context.matchBefore(/\w+/)
// If completion wasn't explicitly started and there
// is no word before the cursor, don't open completions.
if (!context.explicit && !before) return null
return {
from: before ? before.from : context.pos,
options: completions,
validFor: /^\w*$/
}
}
let view = new EditorView({
doc: "// Type a 'p'\n",
extensions: [
basicSetup,
keymap.of([
...defaultKeymap,
...completionKeymap
]),
autocompletion({activateOnTyping: false, override: [myCompletions]})
],
parent: document.body
})