Hi, I am currently developing a new Text Editor, and at the moment I am finding an interesting situation with undo/redo entries. In order to understand the challenge, I will explain first how the editor is built, generally.
The editor has a list of deltas, where a delta is a list of insert operations that take the form:
{ insert: string | { block: BlockType }, glyphs: Array<string>, attributes: { key: value, ... } }
The glyphs parse the insert string and organize each position into a matching position in the array of strings. This is done, as some values are greater than length 1 in actuality, but visually look like a single character, such as an emoji. For example,
string: ‘Hello:family_man_man_girl_girl:World’, glyphs: [ ‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘’, ‘W’, ‘o’, ‘r’, ‘l’, ‘d’ ],
This allows for the cursor to move around with simple mathematics, rather than constantly checking the length of a glyph within the character string.
That said all works well on insert, retain, and delete operations. The issue however arises when I utilize the UndoManager with YText, where it returns the undo/redo statement with a length that is equal to the glyph and not 1. In the above example, the emoji would have length 11.
I am currently using the ytext.applyDelta function to insert text into Yjs.
Does anyone have any suggestions to solve this issue?
Thank you!