Ace 代码编辑器

版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/83053923

代码风格美化编辑器

更多精彩

官网

Ace - The High Performance Code Editor for the Web

API

  1. 设置主题 editor.setTheme("ace/theme/twilight");
  2. 设置程序员语言模式 editor.getSession().setMode("ace/mode/javascript");
  3. 设置制表符大小 editor.getSession().setTabSize(4);
  4. 设置软标签 editor.getSession().setUseSoftTabs(true);
  5. 设置代码自动换行 editor.getSession().setUseWrapMode(true);
  6. 设置当前行高亮 editor.setHighlightActiveLine(false);
  7. 设置边距线显示 editor.setShowPrintMargin(false);
  8. 设置只读 editor.setReadOnly(true);
  9. 重新设置编辑器尺寸 editor.resize();

方法

  1. 赋值 editor.setValue("the new text here");
  2. 取值 editor.getValue();
  3. 获取选择内容 editor.session.getTextRange(editor.getSelectionRange());
  4. 在光标处插入 editor.insert("Something cool");
  5. 获取光标所在行或列 editor.selection.getCursor();
  6. 跳转到指定行 editor.gotoLine(10);
  7. 获取总行数 editor.session.getLength();

事件

  1. 监听内容改变
editor.getSession().on("change", function(e) {

});
  1. 监听内容选择
editor.getSession().selection.on("changeSelection", function(e) {

});
  1. 监听光标移动
editor.getSession().selection.on("changeCursor", function(e) {
	
});

猜你喜欢

转载自blog.csdn.net/asing1elife/article/details/83053923
ACE