I’m facing a strange case where the resolved pos node is not the same as doc.nodeAt()
, I m assuming they should be the same, here’s the details:
My document:
Node: topic, Pos: 0
Node: title, Pos: 1
Node: text, Pos: 2
Node: body, Pos: 14
Node: section, Pos: 15
Node: p, Pos: 16
Node: text, Pos: 17
Node: p, Pos: 35
Node: p, Pos: 37
Node: text, Pos: 38
The cursor is placed in Pos 35 and here’s the proof
state.selection.from is 35
state.selection.to is 35
state.selection.anchor is 35
So I m expecting the resolvedPos.node()
to return the p
node at Pos 35
,
but this is what I m getting:
state.selection.$anchor.node().type.name comes out to 'section'
and If try to use doc.nodeAt
it will return the expected node
state.doc.nodeAt(35).type.name comes out to 'p'
if I replaced the hard coded 35
with state.selection.anchor
the results will be the same.
Is this a bug? or this is by design, due to this issue I m having some hard time telling if the cursor is at the end of line or not and also getting it’s parent.