【问题标题】:Not getting updated cursor position in ace editor?没有在 ace 编辑器中获得更新的光标位置?
【发布时间】:2019-01-31 06:50:34
【问题描述】:

我正在使用 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)
       }
    };

【问题讨论】:

    标签: angularjs ace-editor


    【解决方案1】:

    在某些情况下,更改会在选择更新之前触发,
    尝试使用异步"input" 事件editor.on("input", function() {}),或者在编辑器完全更新后使用某种去抖动超时来运行您的代码。

    【讨论】:

    • 很想为此添加一个额外的 +1。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多