Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【20160909】ACE.js 自定义代码提示,自定义快捷键 #12

Closed
zhongxia245 opened this issue Sep 9, 2016 · 1 comment
Closed
Labels

Comments

@zhongxia245
Copy link
Owner

ACE.js 自定义代码提示

时间:2016-09-09 14:15:41
作者:zhongxia
源码地址:https://github.com/ajaxorg/ace

Ace.js是一款开源的 web编辑器,内置强大的代码提示,快捷键功能。具体了解看官网介绍。

一、背景

由于在产品中,需要用到 输入 数据库名. 弹出数据库下所有表的提示框, 方便用户的使用。
如图:

解决方案

1、使用ACE.js的提示框,替换提示数据【还未实现

在ACE.js上进行扩展,异步获取到表名数据,然后使用ACE 自带的提示框,提示, 这个是一个比较好的解决方案,但是需要去了解下ACE自定义提示是如何实现的,然后进行扩展。 目前还没有研究透。

参考文章

  1. ACE自定义提示如何实现?

2、监听ACE的change事件[如效果图一样]

如果遇到 xxx.这种情况,就把关键字xxx取出,然后去Ajax获取表名列表。
自己实现一个提示框的插件,然后在指定的位置弹出。

//获取当前焦点的位置(提示框使用 position:fixed)
let renderer = editor.renderer;
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
var rect = editor.container.getBoundingClientRect();
pos.top += rect.top - renderer.layerConfig.offset;
pos.left += rect.left - editor.renderer.scrollLeft;
pos.left += renderer.gutterWidth;
@zhongxia245 zhongxia245 added the JS label Sep 10, 2016
@zhongxia245
Copy link
Owner Author

ACE.js 自定义快捷键

editor.commands.addCommand({
      name: "customSave",
      bindKey: {win: "Ctrl-s", mac: "Command-s"},
      exec: function (editor) {
        console.log("customSave", editor.getValue());
      }
    });

@zhongxia245 zhongxia245 changed the title 【20160909】ACE.js 自定义代码提示 【20160909】ACE.js 自定义代码提示,自定义快捷键 Sep 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant