我正在使用ace编辑器来开发angularJs。
每次更改屏幕上的光标位置时,我都希望获得光标位置。
问题是,我总是得到光标的初始位置,而不是最新位置。
下面是我的代码:
this.editorOptions = {
mode: 'groovy',
theme: 'textmate',
showGutter: true, // Enabling line numbers for the editor
useWrapMode: true,
showPrintMargin: false, // Disabling print margin line from the editor
onLoad: (editor) => { // Triggered when the editor gets loaded (i.e., on initial load of the editor)
this.policyEditorBox = editor;
},
onChange: (editor) => { // Triggered on content change of the editor
this.policyEditorBox = editor[1];
console.log("policy editor:",this.policyEditorBox);
console.log(editor[1].selection.cursor.row); //this line always print zero (initial position)
}
};
答案 0 :(得分:0)
在某些情况下,更改会在选择更新之前触发,
尝试使用异步stackTrace
事件"input"
,或在完全更新编辑器后使用某种反跳超时来运行代码。