Call function on autocomplete option selected

122 views
Skip to first unread message

Chris Ainsley

unread,
Oct 20, 2014, 8:19:42 PM10/20/14
to ace-d...@googlegroups.com
I'm wondering if I can bind a function rather than a substitution to an autocomplete option?

I want to be able to select options that are not necessarily subsitutions for the current tokens, but rather, something that may impact one or more other areas of the document. The most generic way to deal with this I guess is via a function callback with a reference to the editor/document?

Thoughts?

Chris

Adam Jimenez

unread,
Oct 21, 2014, 2:37:11 AM10/21/14
to ace-d...@googlegroups.com
This is already possible.
Add an insertMatch function your completer which will act as the callback e.g:

completer = {
    getCompletions: function(editor, session, pos, prefix, callback) {},
    insertMatch: function(editor){}
}

Then in your getCompletions function, return the completions like so:
{
    caption: caption
    value: value
    completer: completer
}

--
You received this message because you are subscribed to the Google Groups "Ajax.org Cloud9 Editor (Ace)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ace-discuss...@googlegroups.com.
To post to this group, send email to ace-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/ace-discuss.
For more options, visit https://groups.google.com/d/optout.



--
Best regards,
Adam Jimenez

ShiftCreate Limited

vanessa....@gmail.com

unread,
Feb 23, 2023, 9:16:43 PM2/23/23
to Ajax.org Cloud9 Editor (Ace)
I am using ace-builds version 1.14.0. I followed this solution, but my custom insertMatch method never got called although my custom "getCompletions" method get called. Any idea why?

protected getCompleterFromPromise(completionPromise: Promise<Ace.Completion[]>, endsWithPeriod: boolean = false): Ace.Completer {
console.log('Hongvan::getCompleterFromPromise');
let retVal: any = {
getCompletions: (editor, session, pos, prefix, callback) => {
console.log('Hongvan::custom getCompletions');
completionPromise.then(valueList => {
const sortedList = sortBy(valueList, ['value']);
callback(null, sortedList);
});
},
insertMatch: (data, options) => {
console.log('Hongvan::custom insertMatch');
}
};

if (!endsWithPeriod) {
retVal = { ...retVal, identifierRegexps: [MATCH_REGEX] };
}
return retVal;

} 
I don't want to listen to "changeSelection" event nor "insertstring" command since these events get fired too often even when I am typing inside the ace editor or when I am not selecting anything in the autocomplete popup.
Any suggestion on how to listen to when an autocomplete option being selected and inserted into the ace editor? Or how to make custom insertMatch to work? I am really stuck. Any help is greatly appreciated. Thanks.

vanessa....@gmail.com

unread,
Feb 27, 2023, 2:40:37 PM2/27/23
to Ajax.org Cloud9 Editor (Ace)

My plan is to listen for insertMatch and call editor.completer.detach.That way after selecting an entry in auto-complete, a user will not see the popup any more (and Enter hit will enter new line for the user instead of selecting the entry again).
The auto-complete popup is annoyingly shown now in our UI after selecting an entry because we have custom logic of showing autocomplete popup for every cursor move based on "changeCursor" event.

Reply all
Reply to author
Forward
0 new messages