版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/83053923
代码风格美化编辑器
更多精彩
- 更多技术博客,请移步 asing1elife’s blog
官网
Ace - The High Performance Code Editor for the Web
API
- 设置主题
editor.setTheme("ace/theme/twilight");
- 设置程序员语言模式
editor.getSession().setMode("ace/mode/javascript");
- 设置制表符大小
editor.getSession().setTabSize(4);
- 设置软标签
editor.getSession().setUseSoftTabs(true);
- 设置代码自动换行
editor.getSession().setUseWrapMode(true);
- 设置当前行高亮
editor.setHighlightActiveLine(false);
- 设置边距线显示
editor.setShowPrintMargin(false);
- 设置只读
editor.setReadOnly(true);
- 重新设置编辑器尺寸
editor.resize();
方法
- 赋值
editor.setValue("the new text here");
- 取值
editor.getValue();
- 获取选择内容
editor.session.getTextRange(editor.getSelectionRange());
- 在光标处插入
editor.insert("Something cool");
- 获取光标所在行或列
editor.selection.getCursor();
- 跳转到指定行
editor.gotoLine(10);
- 获取总行数
editor.session.getLength();
事件
- 监听内容改变
editor.getSession().on("change", function(e) {
});
- 监听内容选择
editor.getSession().selection.on("changeSelection", function(e) {
});
- 监听光标移动
editor.getSession().selection.on("changeCursor", function(e) {
});