slab / delta

Simple and expressive JSON format for describing rich-text content and their changes
https://quilljs.com/docs/delta
BSD 3-Clause "New" or "Revised" License
914 stars 130 forks source link

Fix retain inversion across multiple ops #42

Closed alecgibson closed 5 years ago

alecgibson commented 5 years ago

Consider this base document:

new Delta()
  .insert('123')
  .insert('4', { bold: true });

And this delta:

new Delta().retain(4, { italic: true });

This simply applies italic to the whole document. We'd expect the inverse to remove italic:

new Delta().retain(4, { italic: null });

However, we currently get an inverse op with the wrong retain length:

new Delta().retain(8, { italic: null });

This is because when we parse multiple ops in the inversion, we use the original op's retain value (in this case 4 gets used twice), instead of the length of the individual ops (3 and then 1).

This change updates the inversion to use the correct length for the inverted retain.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 99.029% when pulling 9ffcab4c4429900c030081b5a912c215c5d0702c on alecgibson:fix-invert into 967fe84dfd6634c02be9bb3c46642f1e59384657 on quilljs:master.

jhchen commented 5 years ago

Great PR thanks!