Swapping the data of two Y.Text

I’m probably missing something simple.
I’m trying to swap the data between two Y.Text. This is my current attempt:

const deltaA = yTextA.toDelta()
const deltaB = yTextB.toDelta()

yTextA.delete(0, yTextA.length)
yTextB.delete(0, yTextB.length)


It works fine unless one of them has a header formatting (h1, h2, …), in which case the formatting isn’t swapped. Analyzing their deltas I see that they don’t contain the header formatting information.

How can I effectively swap their data in this case?

Note: I’m binding both Y.Text with Quill editors using y-quill.


Maybe you can try to use two functions which is Y.encodeStateAsUpdate() and Y.applyUpdate().

update = Y.encodeStateAsUpdate(ydocA)
Y.applyUpdate(ydocB, update)

Hi. I have already solved this problem.
The problem was that I initialized Quill with an empty delta: []
The correct way is to initialize Quill with a newline insertion delta: [{ insert: '\n' }]