Autocompletion capability
Hi Inkdrop community, Iām working on a simple autocompletion plugin leveraging CodeMirrorās existing hinting capabilities, and was wondering if anyone had anyone had a simplified āhello worldā example I could use a starting point. I was able to get this to work using vanilla CodeMirror, but for some reason itās not getting picked up by CM embedded in Inkdropās code editor. This seems like it should be simple, but Iām fairly inexperienced JS/React developer, and probably missing something basic.
This is the sample snippet Iām trying to get to work, but itās not really registering so far.
const cm = editor.cm;
const snippets = [
{ text: 'const', displayText: 'const declarations' },
{ text: 'let', displayText: 'let declarations' },
{ text: 'var', displayText: 'var declarations' },
];
// cm.setOption('lineNumbers', false);
// keymap ćęå®
//TODO: implement hinter here
// @ts-ignore
// CodeMirror.registerHelper("gfm", "complete-emoji", anyword);
// keymap ćęå®
cm.setOption('extraKeys', {
'alt-h': function () {
CodeMirror.showHint(cm, function () {
const cursor = cm.getCursor();
const token = cm.getTokenAt(cursor);
const start = token.start;
const end = cursor.ch;
const line = cursor.line;
const currentWord = token.string;
const list = snippets.filter(function (item) {
return item.text.indexOf(currentWord) >= 0;
});
return {
list: list.length ? list : snippets,
from: CodeMirror.Pos(line, start),
to: CodeMirror.Pos(line, end)
};
});
}
});
}
Thanks for the help!