if (body == null) {
editor.getCaretModel().moveToOffset(offset);
}
else {
final TextRange bodyRange = body.getTextRange();
editor.getCaretModel().moveToOffset(bodyRange.containsOffset(offset) ? offset : bodyRange.getEndOffset());
}
}
/**
* must be called not in write action