2016-09-23 38 views
1

我正在使用codemirror編輯器......我想要像樣式列表中的項目,當我做自動完成時appare的功能...所以有任何lib或插件,我可以使用codemirror提供給我比codemirror更多的功能。 .. 注意:我想使用它與codemirror而不是codemirror。 ...提前致謝我可以使用任何lib與codemirror進行自動完成嗎?

回答

1

我成功了。在節目-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; 
} 

在我的主網頁我動態添加的所有表/列作爲對象hintOptions。對於每個表我這樣做:

 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; 

我修改插件/提示/ 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"};}); 
+0

你可以把你的解決方案在jsbin中嗎? – sara

+0

我定義了自己的模式,所以我有我自己的單詞和我自己的功能...我沒有使用sql模式 – sara

1

是的,您可以使用hint addon進行自動填充。 而且您可以通過修改addon/hint/show-hint.css來設置項目的樣式。

+0

如何以不同的方式對各個項目,所以不一樣風格的所有項目,在下拉列表中? – Jan

+1

@Jan如果你只是想對所選項(或者說活動項)進行不同的樣式設計,你應該在'addon/hint/show-hint.css'內改變'li.CodeMirror-hint-active'的CSS規則。或者,如果你想以不同的方式設計每個項目(我無法想象爲什麼),你應該傳遞對象而不是字符串作爲提示項目,這樣你就可以設置每個項目的'className'。有關詳細信息,請查看[提示插件文檔](http://codemirror.net/doc/manual.html#addon_show-hint)。 – olindk

+0

例如,如果你有一個與表名/列名,sql函數(avg,sum,...)和sql關鍵字(select,from,where,...)的下拉菜單,並希望通過使用不同顏色 – Jan

相關問題