我可以将任何库与 codemirror 一起用于自动完成吗?

There are any lib can I use with codemirror for autocomplete?

我正在使用 codemirror 编辑器...我想对列表中的项目进行样式设置,当我执行自动完成时会出现...所以有任何库或插件可以与 codemirror 一起使用,为我提供更多功能比代码镜像。 .. 注意:我想将它与 codemirror 一起使用而不是 codemirror。 ...提前致谢

是的,您可以使用 hint addon 进行自动完成。 您可以通过修改 addon/hint/show-hint.css.

来设置项目的样式

我成功了。在 show-hint.css 中我添加了一些 CSS:

.table.CodeMirror-hint {
  font-weight: bold;
  color: black;
}

.column.CodeMirror-hint {
  font-weight: bold;
  color: black;
}

.keyword.CodeMirror-hint {
  font-weight: bold;
  color: #BF00FF;
}

.builtin.CodeMirror-hint {
  font-weight: bold;
  color: #2E64FE;
}

在我的主网页中,我将所有 tables/columns 作为对象动态添加到 hintOptions。对于每个 table 我都喜欢这样:

        var tcobjs = []; //table columns array of object
        for (j=0; j < tablecolumns.length; j++) {
            tcobjs.push({text:tablecolumns[j],className:"column"});
        }
        hintOptions.tables[table]=tcobjs;

我修改了 addon/hint/sql-hint.js 是这样的:

  var keywords;
  var builtin;

  function getKeywords(editor) {
    var mode = editor.doc.modeOption;
    if (mode === "sql") mode = "text/x-sql";
    var words = {};
    for (var w in CodeMirror.resolveMode(mode).keywords) { words[w] = CodeMirror.resolveMode(mode).keywords[w]; }
    return words;
  }

  function getBuiltin(editor) {
    var mode = editor.doc.modeOption;
    if (mode === "sql") mode = "text/x-sql";
    var words = {};
    for (var w in CodeMirror.resolveMode(mode).builtin) { words[w] = CodeMirror.resolveMode(mode).builtin[w]; }
    return words;
  }

[....]

    keywords = getKeywords(editor);
    builtin = getBuiltin(editor);

[....]

      addMatches(result, search, tables, function(w) {return {text:w,className:"table"};});
      addMatches(result, search, defaultTable, function(w) {return {text:w,className:"table"};});
      if (!disableKeywords)
        addMatches(result, search, keywords, function(w) {return {text:w.toUpperCase(),className:"keyword"};});
      addMatches(result, search, builtin, function(w) {return {text:w.toUpperCase(),className:"builtin"};});