bringNodeForward method
Moves a node one step forward in the z-order.
Swaps the z-index with the next higher node in the visual stack.
Implementation
void bringNodeForward(String nodeId) {
final node = _nodes[nodeId];
if (node == null) return;
runInAction(() {
final sortedNodes = _nodes.values.toList()
..sort((a, b) => a.zIndex.value.compareTo(b.zIndex.value));
final currentIndex = sortedNodes.indexOf(node);
if (currentIndex < sortedNodes.length - 1) {
final nextNode = sortedNodes[currentIndex + 1];
if (node.zIndex.value == nextNode.zIndex.value) {
for (int i = 0; i < sortedNodes.length; i++) {
sortedNodes[i].zIndex.value = i;
}
node.zIndex.value = currentIndex + 1;
nextNode.zIndex.value = currentIndex;
} else {
final currentZ = node.zIndex.value;
final nextZ = nextNode.zIndex.value;
node.zIndex.value = nextZ;
nextNode.zIndex.value = currentZ;
}
}
});
}