Document document = editor.getDocument();
int leftLine = document.getLineNumber(leftStart.getTextOffset());
int rightLine = document.getLineNumber(rightEnd.getTextOffset());
final PsiElement finalRightStart = rightStart;
WriteCommandAction writeCommandAction = new WriteCommandAction(editor.getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
element.deleteChildRange(finalRightStart, rightEnd);
element.getNode().removeRange(leftStart.getNode(), leftEnd.getNode());
}
};
writeCommandAction.execute();
// if parentheses are not in the same line, delete line ending white space and new line
if (leftLine != rightLine) {
deleteLineEditingWhiteSpaceAndNewLine(element);
}