Simplest way to get index from Node object?

Hi Marjin, am I right in saying there is no method on the Node object to get the index? Like, Node.index? There is Node.resolve(pos), that returns a ResolvedPos object where you can finally find the index, but you need the pos in the first place which kind of defeats the point.

Thanks

You mean finding the index of a given child? Yes, you’ll have to iterate through the children manually for that, but in general, that’s usually a bad idea, since nodes have value semantics, meaning their identity (==) doesn’t really mean anything—a given node object might be in the document multiple times, or an equivalent node might be there but it’ll be represented by a different object, so looking for a specific node object is usually not meaningful, and nodes should be tracked by position.

Thanks marijn, praise mirror!

It seems to be the general principle is to iterate through the ‘tree’ where you have parent/child positions, and only convert to node at the last moment.