backspace method
Receive a delete (backspace) request, which should delete the right-most component (constant, dynamic value, etc.).
Implementation
@override
DartBlockValueTreeBooleanNode? backspace() {
if (rightChild != null) {
/// Perform backspace on its right child
rightChild!.backspace();
if (operator == null && rightChild == null) {
/// If the right child becomes null and there is no operator, replace this
/// composed node with its left child (which can be null)
return parent?.replaceChild(this, leftChild) ?? leftChild;
} else {
/// If it still has an operator, return the composed node.
return this;
}
} else {
/// If the right child is already null, disregard if there is an operator
/// and simply replace this composed node with its left child (which can be null).
/// Important: set the left child's parent to the composed node's parent before
/// performing this replacement. This step should probably be integrated into the
/// replaceChild method.
leftChild?.parent = parent;
return parent?.replaceChild(this, leftChild) ?? leftChild;
}
}