/** * Checks if the selection has been removed, or is somewhere where we are not expecting it to be. */ private boolean selectionChangedInappropriately() { // The selection got lost. We need to restore it if (!NativeSelectionUtil.selectionExists()) { return true; } NativeSelectionUtil.cacheClear(); FocusedPointRange<Node> htmlSelection = NativeSelectionUtil.get(); Point<Node> newAnchor = htmlSelection.getAnchor(); if (savedSelectionAnchor.isInTextNode()) { if (savedSelectionAnchorTextNodelet != newAnchor.getContainer() || savedSelectionAnchorOffset != newAnchor.getTextOffset()) { return true; } } else { if (savedSelectionAnchor.getContainer() != newAnchor.getContainer()) { return true; } } Point<Node> newFocus = htmlSelection.getFocus(); if (savedSelectionFocus.isInTextNode()) { if (savedSelectionFocusTextNodelet != newFocus.getContainer() || savedSelectionFocusOffset != newFocus.getTextOffset()) { return true; } } else { if (savedSelectionFocus.getContainer() != newFocus.getContainer()) { return true; } } return false; }