Codemirror 自动完成删除全局建议
Codemirror Autocomplete Remove Global Suggestions
编织:http://kodeweave.sourceforge.net/editor/#d956c96bdee0cdd1ce9193aee78353ac
有谁知道从 Codemirror 的自动完成中删除一些全局变量的有效方法吗?
例如 StyleFix、PrefixFree、Html2Jade 等:不应显示。
这是它的摘要:(来自 https://codemirror.net/doc/manual.html#addon_javascript-hint)
This will simply use the JavaScript environment that the editor runs in as a source of information about objects and their properties.
及相关源码:
var found = [], start = token.string, global = options && options.globalScope || window;
和
function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd);
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
for (var name in obj) maybeAdd(name);//important
}
(来自 https://mikethedj4.github.io/kodeWeave/editor/libraries/codemirror/addon/hint/javascript-hint.js)
其中obj
为global
。
所以如果你想删除一些全局变量
, 只需修改 globalScope
param.
更改此行:
CodeMirror.commands.autocomplete(cm,null, {completeSingle: false});
至
var scope={};
var preventList=['StyleFix', 'PrefixFree', 'Html2Jade','alert'];// map is better
for(var i in window){
if(preventList.indexOf(i)===-1){
scope[i]=window[i]
}
}
CodeMirror.commands.autocomplete(cm,null, {completeSingle: false,globalScope:scope});
现场演示:
https://mikethedj4.github.io/kodeWeave/editor/#cf4c4aa884b6ddb30c4ac79dd8bf3997
编织:http://kodeweave.sourceforge.net/editor/#d956c96bdee0cdd1ce9193aee78353ac
有谁知道从 Codemirror 的自动完成中删除一些全局变量的有效方法吗?
例如 StyleFix、PrefixFree、Html2Jade 等:不应显示。
这是它的摘要:(来自 https://codemirror.net/doc/manual.html#addon_javascript-hint)
This will simply use the JavaScript environment that the editor runs in as a source of information about objects and their properties.
及相关源码:
var found = [], start = token.string, global = options && options.globalScope || window;
和
function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd);
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
for (var name in obj) maybeAdd(name);//important
}
(来自 https://mikethedj4.github.io/kodeWeave/editor/libraries/codemirror/addon/hint/javascript-hint.js)
其中obj
为global
。
所以如果你想删除一些全局变量
, 只需修改 globalScope
param.
更改此行:
CodeMirror.commands.autocomplete(cm,null, {completeSingle: false});
至
var scope={};
var preventList=['StyleFix', 'PrefixFree', 'Html2Jade','alert'];// map is better
for(var i in window){
if(preventList.indexOf(i)===-1){
scope[i]=window[i]
}
}
CodeMirror.commands.autocomplete(cm,null, {completeSingle: false,globalScope:scope});
现场演示: https://mikethedj4.github.io/kodeWeave/editor/#cf4c4aa884b6ddb30c4ac79dd8bf3997