How to get the absolute position of a sibling node?

Let’s say I have a bullet list with three list items and one of them is selected. How can I get the absolute position of the sibling before or after the selected item? I looked through the ResolvedPos methods, but couldn’t find a way to do this. The nodeBefore and nodeAfter properties give the correct node, but I need the position of the node and not the node itself.

My goal is being able to swap two items in a list by deleting an item and inserting it before or after its sibling. Maybe there’s a better way to achieve the swapping functionality?

Where is your resolved position pointing? If it’s before the node, then $pos.pos - $pos.nodeBefore.nodeSize gives you the position before the previous sibling, and $pos.pos + $pos.nodeAfter.nodeSize would produce the position before the next sibling.

2 Likes

Thanks, that works!