Does the selection produced by TextSelection.between(doc.resolve(0), doc.resolve(doc.firstChild.nodeSize)) do what you are looking for? It’ll create a valid text selection from the first inline position in the doc to the last one in the body, which should still allow you to delete or overwrite the body’s content.
Can you share your editor content? I’m guessing you must have something like <blockquote><p></p></blockquote> in which case 0 would be the document, 1 would be in the blockquote but before the text content of the paragraph, and 2 would be the first text position. Normally 1 would be the first text position if the editor contained <p></p>
Oops, my mistake, I was using `TextSelection.create`.
With `TextSelection.between`, it reports error:
index.js:295 Uncaught TypeError: Cannot read properties of undefined (reading 'inlineContent')
at _TextSelection.between (index.js:295:27)
I am also wondering if say a codeblock is at the begining of body, the codeblock would remain there (although the content is cleared) after hitting delete with TextSelection.between, right?
But a valid text selection in body is not “enough” or identical to the AllSelection. Say if a codeblock is at the begining of body, the codeblock would remain there (although the content is cleared) after hitting delete with TextSelection.between, while nothing left with AllSelection.
Besides, I have also defined some captioned-image/table node. If it is the last node, TextSelection.between would make the selection goes into the caption (instead of including the whole image). And I have some logic to prevent the partial deletion, which would surprise the use when one hits delete with no effect. To this regard, it seems tr.setSelection(TextSelection.create(doc, 1, doc.firstChild.nodeSize-1)) has the closest behavour to AllSelection.
I guess I find a bug. If the last cell of the table is empty, TextSelection.between would skip the whole table when it tries to find a valid text selection. And if I fill it with some text, then TextSelection.between would locate in the cell.