isOperatorSelected method
Returns whether the selection covers an operator of the given
binaryExpression.
Implementation
bool isOperatorSelected(BinaryExpression binaryExpression) {
AstNode left = binaryExpression.leftOperand;
AstNode right = binaryExpression.rightOperand;
// Between the nodes.
if (selectionOffset >= left.end &&
selectionOffset + selectionLength <= right.offset) {
return true;
}
// Or exactly select the node (but not with infix expressions).
if (selectionOffset == left.offset &&
selectionOffset + selectionLength == right.end) {
if (left is BinaryExpression || right is BinaryExpression) {
return false;
}
return true;
}
// Invalid selection (part of node, etc).
return false;
}