获取光标处的增量(无选择)而不拆分它

Ric*_*Ric 3 quill

这是一个带有属性的增量:

试图获得增量

editor.getContents(range.index, range.length);
Run Code Online (Sandbox Code Playgroud)

返回

  Delta: {
    ops: []
  }
Run Code Online (Sandbox Code Playgroud)

这是预期的 - range.length 为 0。

有没有办法返回整个增量(从左到右),所以它看起来像这样:

Delta: {
   ops: [
    {
      attributes: { test: '123' },
      insert: 'A selection'
    },
    ...
  ]
}
Run Code Online (Sandbox Code Playgroud)

jhc*_*hen 5

假设一个稍微复杂的例子来消除歧义并假设 test 123 属性是用类 Attributor 实现的,给定文档:

<div class="ql-editor">
  <p><strong>ab</strong><span class="ql-test=123">cd<em>ef</em></span></p>
</div>
Run Code Online (Sandbox Code Playgroud)

但是,我认为您要问的是当用户的光标位于“e”和“f”之间时获取“cdef”文本的增量,因此您的范围是index: 5.

这是一个实验性/未记录的 API,但quill.scroll.path(5)会为您提供一个数组,[[blockBlot, 0], [inlineBlot, 2], [italicBlot, 1]]并且在这种情况下您想要的污点是第二个,因此通过将偏移量相加,您将获得 2 (0 + 2),然后您可以调用 quill.getContents( 2、blot.length())。

如果类是唯一的(或者您可以通过其他方式访问 DOM 节点),您还可以执行以下操作:

const Parchment = Quill.import("parchment");
let node = document.querySelector('.ql-test-123');
let blot = Parchment.find(node);
let offset = quill.scroll.offset(blot);

quill.getContents(offset, blot.length());
Run Code Online (Sandbox Code Playgroud)