gpt4 book ai didi

javascript - CodeMirror - 更新选择

转载 作者:行者123 更新时间:2023-11-30 00:35:05 27 4
gpt4 key购买 nike

因此在 CodeMirror 中,您可以通过调用 getCursor() 来进行选择。执行以下操作:

cm.getCursor(true) // start selection
cm.getCursor(false) // end selection

这为您提供了一个对象,用于保存光标的行和 ch 位置。有了它你可以 mark text :

cm.markText(startPos, endPos, options)

一旦我标记了文本,是否可以更新它? (实际上没有删除它并添加新标记)
例如:

var t = cm.markText({ line:0, ch:0 }, { line:0, ch:10 });
t.setEnd({ line:0, ch:5 });

编辑因为有些人可能会寻找它。这是修改标记文本的方式:

var t = editor.markText({ line:0, ch:0 }, { line:0, ch:10 }, {className: someClass});
t.clear();
t = editor.markText({ line:0, ch:0 }, { line:0, ch:5 }, {className: someClass});

最佳答案

没有。标记的工作方式实际上与您的想法相反 - 线条指向并记住它们的标记,反之亦然。

See the documentation about TextMarker from the source code .

这是相关的引用:

Line objects hold arrays (markedSpans) containing {from, to, marker} object pointing to such marker objects, and indicating that such a marker is present on that line.

关于javascript - CodeMirror - 更新选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27557080/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com