1. ace-editor編輯器只讀狀態:editor.setReadOnly(true); // false to make it editable
2. ace-editor設置程序語言模式:editor.session.setMode("");
3. ace-editor獲取光標所在行列:editor.selection.getCursor();
4. ace-editor跳轉至行:editor.gotoLine(lineNumber);
5. ace-editor設置默認制表符大小:editor.session.setTabSize(4);
6. ace-editor使用軟標簽:editor.session.setUseSoftTabs(true);
7. ace-editor設置字體大小:document.getElementById('editor').style.fontSize='12px';
8. ace-editor設置代碼折疊:editor.session.setUseWrapMode(true);
9. ace-editor設置高亮:editor.setHighlightActiveLine(false);
10. ace-editor是否顯示中間的垂直中線(打印邊距可見度):editor.setShowPrintMargin(false);
11. 搜索:
editor.find('needle', { backwards: false, wrap: false, caseSensitive: false, wholeWord: false, regExp: false });
editor.findNext();
editor.findPrevious();
下列選項可用於您的搜索參數:
needle: 要查找的字符串或正則表達式 backwards: 是否反向搜索,默認為false wrap: 搜索到文檔底部是否回到頂端,默認為false caseSensitive: 是否匹配大小寫搜索,默認為false wholeWord: 是否匹配整個單詞搜素,默認為false range: 搜索范圍,要搜素整個文檔則設置為空 regExp: 搜索內容是否是正則表達式,默認為false start: 搜索起始位置 skipCurrent: 是否不搜索當前行,默認為false
替換單個字符:
editor.find('foo'); editor.replace('bar');
替換多個字符:
editor.replaceAll('bar'); editor.replaceAll使用前需要先調用editor.find(‘needle’, …)
12. 事件監聽
監聽事件 onchange editor.session.on('change', function(delta) { // delta.start, delta.end, delta.lines, delta.action }); 監聽事件 selection editor.session.selection.on('changeSelection', function(e) { }); 監聽事件 cursor editor.session.selection.on('changeCursor', function(e) { });
13. 添加新命令以及綁定鍵盤按鍵
需要將指定鍵綁定到一個自定義函數: editor.commands.addCommand({ name: 'myCommand', bindKey: { win: 'Ctrl-M', mac: 'Command-M' }, exec: function (editor) { //... }, readOnly: true // false if this command should not apply in readOnly mode });