编织:http : //kodeweave.sourceforge.net/editor/#d956c96bdee0cdd1ce9193aee78353ac
有谁知道从Codemirror的自动完成功能中删除某些全局变量的有效方法吗?
例如StyleFix,PrefixFree,Html2Jade等:应该不可见。
以下是其摘要:(摘自https://codemirror.net/doc/manual.html#addon_javascript-hint)
这将仅使用编辑器在其中运行的JavaScript环境作为有关对象及其属性的信息源。
以及相关的源代码:
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
参数。
更改此行:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句