【问题标题】:How to get the cursor position (not row or column) in Ace Editor?如何在 Ace Editor 中获取光标位置(不是行或列)?
【发布时间】:2017-01-26 07:00:30
【问题描述】:

有没有办法在 Ace Editor 中获取光标位置(不是行和列)。

例如,如果 Ace Editor 的内容如下:

Hello
World

光标在“世界”中的“我”之后。位置或索引将是 7 或 8(如果计算换行符)。

有没有办法获取位置?

【问题讨论】:

    标签: ace-editor


    【解决方案1】:

    Ace 调用{row, column} 对象的位置,以及自文档开始索引以来的字符数。
    您可以使用editor.session.doc.positionToIndex 方法https://github.com/ajaxorg/ace/blob/v1.2.6/lib/ace/document.js#L678 将位置转换为索引,但请注意,此方法不是很快,因为它必须遍历整个文档,因此请尽量少用它和indexToPosition

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多