isNodeSelected method
Implementation
bool isNodeSelected(String nodeId) {
if (!_selectionManager.hasSelection) return false;
final state = _selectionManager.state;
final anchor = state.anchor;
final focus = state.focus;
if (anchor == null || focus == null) return false;
// O(1) document-order lookup via the cached position index.
// Replaces the O(n) getNodePath scan that was a major bottleneck
// during drag selection on large documents.
final nodePos = nodePosition(nodeId);
final anchorPos = nodePosition(anchor.nodeId);
final focusPos = nodePosition(focus.nodeId);
if (nodePos == null || anchorPos == null || focusPos == null) return false;
final basePos = anchorPos <= focusPos ? anchorPos : focusPos;
final extentPos = anchorPos <= focusPos ? focusPos : anchorPos;
return nodePos >= basePos && nodePos <= extentPos;
}