ACE Editor Autocomplete - custom strings

前端 未结 2 1130
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 10:54

I\'m using ACE Editor within a Chrome extension. I\'m using ACE\'s Autocomplete feature but I want to be able to completely define a list of static strings to use for the au

相关标签:
2条回答
  • 2020-12-14 11:33

    you need to add a completer like this

    var staticWordCompleter = {
        getCompletions: function(editor, session, pos, prefix, callback) {
            var wordList = ["foo", "bar", "baz"];
            callback(null, wordList.map(function(word) {
                return {
                    caption: word,
                    value: word,
                    meta: "static"
                };
            }));
    
        }
    }
    
    langTools.setCompleters([staticWordCompleter])
    // or 
    editor.completers = [staticWordCompleter]
    
    0 讨论(0)
  • 2020-12-14 11:41

    If you want to persist the old keyword list and want to append a new list

    var staticWordCompleter = {
        getCompletions: function(editor, session, pos, prefix, callback) {
            var wordList = ["foo", "bar", "baz"];
            callback(null, [...wordList.map(function(word) {
                return {
                    caption: word,
                    value: word,
                    meta: "static"
                };
            }), ...session.$mode.$highlightRules.$keywordList.map(function(word) {
            return {
              caption: word,
              value: word,
              meta: 'keyword',
            };
          })]);
    
        }
    }
    
    langTools.setCompleters([staticWordCompleter])
    // or 
    editor.completers = [staticWordCompleter]  
    
    0 讨论(0)
提交回复
热议问题