slab / quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility

Home Page:https://quilljs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parent Parent's cache is not getting invalidated

vinodgubbala opened this issue · comments

When a nested element is being modified, the cache of the parent's parent is not being invalidated.
This is causing the lengths and index calculations being wrong.

Steps for Reproduction

it('Cache issue', async () => {
  let quillRef = {};
  render(<QuillEditor html={`
    <p><b>1<i>2</i>3</b></p>
    <p><i>567</b=i></p>
  `} quillRef={quillRef}/>);
  const quill = quillRef.quill;
  
  // get all italics
  const italics = quill.scroll.descendants(Italic);

  // Get index of italic, so cache is generated
  const index1 = quill.getIndex(italics[0]);
  expect(index1).toBe(1);

  //replace italic with longer text
  italics[0].replaceWith('text', '21234');

  // get index of next line   
  const index2 = quill.getIndex(italics[1]);
  expect(index2).toBe(8); // But 4
});

Expected behavior: Index or length to be recalculated

Actual behavior: Index or length being returned from last calculation

Platforms: Any platform

Version: 2.0.2

I had to do this as a workaround right now.

while (parent !== blot.scroll) {
  if ('cache' in parent) {
    // @ts-ignore
    parent.cache = {};
  }
  parent = parent.parent;
}