function findCommonAncestor() {
if (selectedNodes.size !== 2) return null;
const nodes = Array.from(selectedNodes);
let [node1, node2] = nodes;
const ancestors1 = new Set();
let current = node1;
while (current) {
ancestors1.add(current.data["@id"]);
current = current.parent;
}
current = node2;
while (current) {
if (ancestors1.has(current.data["@id"])) {
return current;
}
current = current.parent;
}
return null;
}