【问题标题】:How to set the caret to a specific position in etherpad?如何将插入符号设置到 etherpad 中的特定位置?
【发布时间】:2025-12-05 21:05:03
【问题描述】:

我正在创作一个插件,并且在插件的某些操作中,插入符号移回 0:0。我可以用

获得插入符号的位置
exports.aceKeyEvent = function(hook_name, args, cb) {
        line = args.editorInfo.ace_caretLine();
        char = args.editorInfo.ace_caretColumn();
}

.. 但到目前为止我还没有找到任何设置插入符号的东西。假设有一个 Set 选择方法,但文档没有给我任何提示。

【问题讨论】:

  • Etherpad / ace 编辑器创建一个 iframe,其中包含一个带有标签的文档:<body contenteditable="true"> 也许在标准 html 操作 / javascript 中设置插入符号就足够了。
  • 我得到一个提示,ep_citation 正在做那条线上的工作,...

标签: etherpad


【解决方案1】:

感谢 John Mc Lear,我们找到了解决方案。 example

只有在调用 ace_replaceRange 之后,才会调用 ace_performSelectionChange 在 acekeyEvent 挂钩中设置插入符号的位置,在这里我们使用 ace_callWithAce 获取 ace 对象。

但是,这在 postAceInit 挂钩中有效。

        context.ace.callWithAce(function(ace) {
            ace.ace_performSelectionChange([line - 1, char], [line - 1, char], false);
        }, 'padsearch_callstack', true);

【讨论】:

    最近更新 更多