How to select all the content of a node (not the node)

I have a schema with a content body foot for the top node.

Both the children contain block+ content and have isolating and defining true. And contenteditable is false for foot.

When one is edting in body, I want all it’s content to be selected with mod-a.

Now I come up with `tr.setSelection(TextSelection.create(doc, 1, doc.firstChild.nodeSize-1))`.

Everything works except:

  1. A waring in console: TextSelection endpoint not pointing into a node with inline content (body). I think it is explained in Why is the Ctrl+A selection different from selecting the whole document with the mouse?
  2. Cursor goes to foot(seems blured as it has contenteditable false) after hitting delete. While I want to keep it in body for pleasent editing.

I wonder what is recommended way to do it right.

Does the selection produced by TextSelection.between(0, 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.

Yes. But it warns: TextSelection endpoint not pointing into a node with inline content (doc)

and the cursor position issue remain the same.

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>

It does this for a selection created with TextSelection.between? Are you sure?

1 Like

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?

You are right. I have a body and foot node under the top document and I am talking about editing in the body node.

Are you passing it resolved positions or just numbers?