Codemirror函数和扩展脚本

时间:2013-11-30 01:32:21

标签: javascript codemirror

所以我的文件js-hint以及foldFunction

我不希望它是一个额外的按键设置,我宁愿在我的选项面板中将它打开或关闭。这给我带来js-hint部分,我希望它一直在运行,而不是只在它为一个单词打开时。

有没有经验的人有幸这么做吗?我已经知道我将如何得到foldFunction我相信:

extraKeys: { "Ctrl-Q": function (cm) { CollapseFunc(cm, cm.getCursor().line); },"Ctrl-Space": "autocomplete" }

转向:

var a= document.getElementById('checkmark');
if(a.checked === true){
  CodeMirror.defineOptions...
}

我不确定如何进一步说明这一点,因为我不肯定将OptionDutter定义为false会在页面加载后改变它。

有人有任何建议吗?

1 个答案:

答案 0 :(得分:0)

实例化代码镜像后,您可以使用codemirror setOption方法启用或禁用foldGutter。每当从隐藏文本字段读取新输入时,将触发以下codemirror事件处理程序。如果选中该复选框并且自动完成菜单尚未打开,则会触发execCommand方法打开自动完成菜单。这会在您键入时产生提示。我已将此添加到我的codemirror实现中,并将对其进行测试。

<label><input type="checkbox" id="AutoCompleteEnabled" /> Enable Autocomplete </label>
<label><input type="checkbox" id="FoldGutterEnabled" /> Enable Code Folding </label>
<script>
  $(function(){
    $("#FoldGutterEnabled").on("click", function(){
      CM.setOption("foldGutter", this.checked);
    });
    CM.on("inputRead", function(cm){
      // Show the autocomplete menu when input is changed if the Enable Auto Hint checkbox is checked and the autocomplete menu is not already open.
      if($("#AutocompleteEnabled:checked").length==1 && $(".CodeMirror-hints").length==0) CM.execCommand("autocomplete");
    });
  });
</script>

如果您正在寻找不同的东西,请告诉我。