react-ace icon indicating copy to clipboard operation
react-ace copied to clipboard

Adding completers and Mutliple editors cause completers to fire multiple times

Open dakotalightning opened this issue 7 years ago • 2 comments

I don't know if this is the correct way to add completers to the editor, I haven't seen any documentation on the right way to do it using react-ace via brace in a component.

I'm adding them in the onLoad of the editor; I have multiple editors on the page. When multiple editors are loaded, the completers fire for each one loaded. The editor results in duplicate completions.

Here is how they are loaded in the onLoad event.

var completers = [ 
    { 
        name: 'name', 
        value: 'val', 
        score: 100, 
        meta: 'item' 
    },
    ...
];

editor.completers.push({
    getCompletions: function(editor, session, pos, prefix, callback) {
        callback(null, completers);
    }
});

I'm not sure if this a bug or an issue with my implementation.

Thanks for the help in advanced.

dakotalightning avatar Nov 16 '16 02:11 dakotalightning

+1, what's the correct way for this issue?

Emiya0306 avatar Jul 08 '19 04:07 Emiya0306

When used with ext-language_tools which always uses a singleton to set editor.completers, pushing a new completer to it always populate it over and over therefore at the end you will have completers with count of render/mount times. So I would simply suggest setting a copy of completer before setting current editor such as editor.completers = [...editor.completers, {your completer}] to keep ext-language_tools singleton untouched.

renjfk avatar Oct 01 '20 07:10 renjfk