CodeMirror自动完成自定义列表 [英] CodeMirror AutoComplete Custom List

查看:760
本文介绍了CodeMirror自动完成自定义列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在代码镜像中重新设置自动完成功能。我想做的是两件事(我都在努力):

I am having a bit of difficultly re the auto complete function in code mirror. What I am trying to do is two things (both which I am struggling with):

1)我想为两个 HTML启用自动完成功能 JavaScript
目前,我只能使用以下命令一次完成一项工作:

1) I want to enable auto complete for both HTML and JavaScript. Currently I can only get one working at a time using e.g.:

 CodeMirror.commands.autocomplete = function (cm) {
     CodeMirror.showHint(cm, CodeMirror.hint.html);
 };

如何添加 CodeMirror.hint.javascript HTML 到列表?

2)(种类更多)-如何将自定义变量添加到 HTML 的提示列表中,该区域是从ajax调用中检索的.....

2) (Kind of more important) -- How can I add custom variables to the list of hints from HTML which area retrieved from an ajax call.....

ie我想让下拉列表显示html提示中的当前数据列表,但是然后添加自定义条目,例如 ## SomeCode1 ## ## SomeCode2 ##

i.e. I want to have the drop down show up with the current list of data from the html hints, but then add custom entries such as ##SomeCode1## and ##SomeCode2##

我在这里有两个问题。首先,当我尝试对html-hint.js文件中的值进行硬编码时,所有值都附加了< ...,这不是我想要的。

I have two problems here. First when I try to hard code the values in the 'html-hint.js' file the values all get appended with <... which is not what I want.

第二个问题是,我认为我必须正确编写一个新的 html-hint.js文件吗?我的意思是,没有办法在上面的 CodeMirror.hint.html 的'options'参数中传递任何内容,以实质上合并两个列表。

The second problem, kind of, is that I believe I have to write a new 'html-hint.js' file correct? I mean there is no way to pass anything in the 'options' parameter in the CodeMirror.hint.html above is there, to essentially merge two list.

我来宾一个和两个都想到了...将两个自动完成的值列表合并在一起。

I guest one and two are kind of the same come to think of it... Merging two lists of values for auto complete together.

我猜框架中已经没有东西了,我必须编写一个自定义提示文件,对吗?

I am guessing there is nothing already in the framework and I have to write a custom hint file, correct?

任何指针都将不胜感激。示例代码会很棒。

Any pointers would be appreciated. Sample code would be awesome.

推荐答案

如果不指定提示函数,则show-hint插件将采用为本地模式,在该模式下完成,因此将是 JavaScript 中的 CodeMirror.hint.javascript 代码以及HTML中的 CodeMirror.hint.html

If you do not specify a hint function, the show-hint addon will take the hint helper function defined for the local mode at which the completion happens, so that will be CodeMirror.hint.javascript in JavaScript code, and CodeMirror.hint.html in HTML.

如果需要添加自己的完成逻辑,则可以可以通过简单地用您自己的代码覆盖它们来替换(或包装)这些函数。

If you need to add your own completion logic, you can replace (or wrap) these functions by simply overwriting them with your own code.

以下是一个粗略的示例hack,总是向JavaScript补全中添加 bozo:

Here is a crude example hack that always adds "bozo" to JavaScript completions:

var orig = CodeMirror.hint.javascript;
CodeMirror.hint.javascript = function(cm) {
  var inner = orig(cm) || {from: cm.getCursor(), to: cm.getCursor(), list: []};
  inner.list.push("bozo");
  return inner;
};

这篇关于CodeMirror自动完成自定义列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆