Resolved: General question positions of first indexes `<p><span>•Add` is index 1?

Hi Marijn,

At Storyscript, we’re looking at a possible peculiarity with positions in Prosemirror that we’re trying to understand.

I have the following document structure and my caret is at the •:

<div>
<span class="text">
•Text
</span>
</div>

I modified the plugin example for showing selection size to also show the index of “from” & “to” I was expecting that this position would show as “2” based on the counting algorithm described in the intro guide, but I am seeing “1”.

This seems confusing because I would want to have a distinct position for the position between <div>•<span ...

<div>•
<span class="text">
Text
</span>
</div>

Is this an issue?

Thanks,

Cole

Is the <div> the outer document container? Positions are counted from the start of the top nodes content, so the top node’s open token doesn’t count (you can’t put your cursor in front of it).

It was not the outside container, but I think I figured out the issue.

My toDom was using a nested structure like this:

      toDOM(node) {
        console.log(node.attrs);
        return [
          "div",
          {
            class: `block prose ${node.attrs.kind ?? ProseKind.paragraph}`,
            ...idAttrs.toDOMAttrs(node),
          },
          ["span", { class: "text" }, 0],
        ];
      },

So, it doesn’t make sense that we could have a position in between these two elements. I think I was experiencing issues with the gap cursor it that it would allow me to drop things before that span, which caused me to be confused. We removed the extra span and we’ll go forwards with that!

Thanks for the quick response.