王牌编辑器自动完成 [英] Ace editor auto completion

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

问题描述

我在SQL模式王牌编辑工作。我跟着这个链接启用自动完成: https://github.com/ ajaxorg / ACE / BLOB /主/演示/ autocompletion.html 。它通常效果很好。不过,我想调整的自动完成,以满足我的要求,进一步多一点。这里的愿望清单:


  1. 我希望提出的SQL关键字都是大写。他们都在小写默认;

  2. 我发现当我键入一些文字,我的previously输入单词添加到字典中的建议,这是很好的。我可以以编程方式甚至在任何在编辑器中键入的建议词典添加更多的单词。我需要这样做的原因是,我想preLOAD一些表名和字段名到字典中。

我是新来这个真棒编辑器。我希望得到有关如何调整自动完成功能的一些方向。谢谢你。


解决方案

有一个拉请求添加更好的完成对SQL Server模式的 https://github.com/ajaxorg/ace/pull/2460 ,SQL模式可以处理相同的方式。

添加更多的话,你需要实现一个自定义的完成者,这是简单的:

\r
\r

<!DOCTYPE HTML>\r
< HTML和GT;\r
< HEAD>\r
  &所述; SCRIPT SRC =htt​​p://ajaxorg.github.io/ace-builds/src/ace.js>\r
  < / SCRIPT>\r
  &所述; SCRIPT SRC =htt​​p://ajaxorg.github.io/ace-builds/src/ext-language_tools.js>\r
  < / SCRIPT>\r
  <风格>\r
    #editor {立场:绝对的;顶部:0;左:0;右:0;底部:0;}\r
  < /风格>\r
< /头>\r
<身体GT;\r
 < D​​IV ID =编辑器>\r
preSS按下Ctrl + Space< / DIV>\r
< /身体GT;\r
<脚本>\r
  编辑= ace.edit(编辑)\r
  editor.setOptions({\r
    //模式:ACE /模式/ JavaScript的\r
    enableBasicAutocompletion:真\r
  });\r
  editor.completers.push({\r
    getCompletions:功能(编辑会话,POS,preFIX,回调){\r
      回调(NULL,[\r
        {值:富,分数:1000元:定制},\r
        {值:酒吧,分数:1000元:定制}\r
      ]);\r
    }\r
  })\r
< / SCRIPT>\r
< / HTML>

\r

\r
\r

亦见的https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor

I am working with ace editor in sql mode. I followed this link to enable auto completion: https://github.com/ajaxorg/ace/blob/master/demo/autocompletion.html. It generally works well. However, I want to tweak the auto completion a bit more in order to fulfill my further requirements. Here's wish list:

  1. I hope the sql key words suggested are all in upper case. They are all in lower case by default;
  2. I found as I type in some words, my previously input words are added to the suggestion dictionary, which is good. Can I programmatically add more words in the suggestion dictionary even before anything is typed in the editor. The reason I need this is that I want to preload some table names and field names into the dictionary.

I am new to this awesome editor. I hope to get some direction on how to tweak the auto completion feature. Thanks.

解决方案

There is a pull request to add better completion for sql server mode https://github.com/ajaxorg/ace/pull/2460, sql mode could be handled same way.

to add more words you need to implement a custom completer, which is simple:

<!DOCTYPE html>
<html>
<head>  
  <script src="http://ajaxorg.github.io/ace-builds/src/ace.js">
  </script> 
  <script src="http://ajaxorg.github.io/ace-builds/src/ext-language_tools.js">
  </script> 
  <style>
    #editor { position: absolute; top: 0; left: 0; right: 0; bottom: 0;}
  </style>
</head>
<body>
 <div id="editor">
press ctrl+space</div> 
</body>
<script>
  editor = ace.edit("editor")
  editor.setOptions({
    // mode: "ace/mode/javascript",
    enableBasicAutocompletion: true
  });
  editor.completers.push({
    getCompletions: function(editor, session, pos, prefix, callback) {
      callback(null, [
        {value: "foo", score: 1000, meta: "custom"},
        {value: "bar", score: 1000, meta: "custom"}
      ]);
    }
  })
</script>
</html>

see also https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor

这篇关于王牌编辑器自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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