Long story short, I am trying to implement paging. I have nodes to represent the page with content. I’ve read the related topic(s) on this forum and decided to take the following approach:
Upon initial load of an existing text file (which is not split into pages), I put it in a single page and then run an algorithm that picks the right places to
tr.split(), which creates the following pages and spreads the rest of the content into them. So far that works fine.
Another aspect is moving content between pages upon text manipulation. I decided to move the page boundary instead of moving the content. Example doc with nodes and positions:
<doc>1 1<page id="p1">2 2<foo>AAA</foo>7 7<bar>BBB</bar>12 12<baz>CCC</baz>17 17</page>18 18<page id="p2">19 19<foo>AAA</foo>24 24<bar>BBB</bar>29 29<baz>CCC</baz>34 34</page>35 35</doc>
To slice the
</page><page id="p2"> and insert it between
</bar>|HERE|<baz> I am using
const state = view.state; const boundarySlice = state.doc.slice(17, 19); const tr = state.tr; tr.delete(17, 19); tr.replace(12, boundarySlice); view.dispatch(tr);
Is that the correct approach?