CodeMirror使用多个提示源进行自动完成 [英] CodeMirror Use multiple hint sources for autocomplete

查看:647
本文介绍了CodeMirror使用多个提示源进行自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以包括多个提示来源以实现自动完成?我试过了:

Is it possible to include multiple hint sources for autocomplete? I tried this:

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

,但它似乎只包括最后一个被引用的源文件,而忽略其余的文件。有什么简单的方法吗?

but it seems to just include the last source file that is referenced and ignore the rest. Is there any easy way of doing this?

推荐答案

我在另一个问题中找到了我的问题的答案,所以请原谅使这个问题有点多余。我需要做的是找出在调用自动​​完成功能时当前处于活动状态的模式(我正在使用混合模式)。首先需要执行以下操作:

I found the answer to my question in another question so please excuse me if that makes this question a little redundant. What I needed to do is find out what mode is currently active (i am using a mixed mode) at the time autocomplete is called. To do this first I needed the mode:

var mode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(POS).state).mode.name;

我发现此处。对于我的情况,我想在调用自动​​完成功能时执行此操作,因此我的函数应如下所示:

which I found here. For my situation I wanted to do that whenever the autocomplete was called so my function looks like this:

CodeMirror.commands.autocomplete = function(cm) {
    var doc = cm.getDoc();
    var POS = doc.getCursor();
    var mode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(POS).state).mode.name;

    if (mode == 'xml') { //html depends on xml
        CodeMirror.showHint(cm, CodeMirror.hint.html);
    } else if (mode == 'javascript') {
        CodeMirror.showHint(cm, CodeMirror.hint.javascript);
    } else if (mode == 'css') {
        CodeMirror.showHint(cm, CodeMirror.hint.css);
    }
};

现在,每当调用自动完成功能时,它都会检查编辑器在文档中特定位置的模式

Now whenever the autocomplete is called it checks what mode the editor is in at that specific point in the document.

这篇关于CodeMirror使用多个提示源进行自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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