// Valid position for cursor, so stop where we are:
if (!isKnownInvalidTopContainerForCursor(container)) {
return point;
}
ContentNode nodeAfter = point.getNodeAfter();
ContentNode newContainer;
if (nodeAfter == null) {
// place the cursor in the right-most valid child of the current container
newContainer = validContainerView.getLastChild(container);
} else {
// we want to place the cursor at the end of the previous node
newContainer = validContainerView.getVisibleNodePrevious(nodeAfter);
if (newContainer != null) {
// Special-case: if nodeAfter is already valid, find the previous valid point:
if (newContainer.equals(nodeAfter)) {
// Check to see if we've found ourselves before a visible, valid point:
newContainer = validContainerView.getVisibleNodePrevious(nodeAfter.getParentElement());
if (newContainer == nodeAfter.getParentElement()) {
return Point.before(validContainerView, nodeAfter);
}