I’m making my Lua engine on CodeMirror (+ luaparser), I changed the show-hint.js addon code a bit, and I want to make sure that the cursor is created on each “$” character, which will be replaced with a void before inserting into the text. I already have an array of all coordinates for cursors, but I can’t find an API anywhere on the Internet to create cursors.
ps. Cursors, I mean, those that are created by the combination “Ctrl + LMB”
pick: function(data, i) {
const completion = data.list[i], self = this;
this.cm.operation(function() {
const txt = completion.text;
const indices = [];
let minuses = 0;
for(let i=0; i<txt.length; i++) { // Find "$"
if (txt[i] === "$") {
indices.push(i-minuses);
minuses++;
}
}
completion.text = completion.text.replace('$', ''); // Remove "$"
if (completion.hint)
completion.hint(self.cm, data, completion);
else
self.cm.replaceRange(getText(completion), completion.from || data.from,
completion.to || data.to, "complete");
CodeMirror.signal(data, "pick", completion);
if(indices.length > 0){
for (const indicesKey in indices) {
// TODO: Creating cursors
// Bad try: self.cm.setCursor(data.from.line, data.from.ch+indices[indicesKey]);
}
}
self.cm.scrollIntoView();
});
if (this.options.closeOnPick) {
this.close();
}
}
self.cm.addSelection({
line: 32,
ch: 5
});
self.cm.addSelection({
line: 33,
ch: 2
});