ISelection originalSelection = selectionProvider.getSelection();
if (selectionProvider instanceof StructuredSelectionProvider && originalSelection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) originalSelection;
// make sure the old selection is actually still valid
if (!textSelection.isEmpty() && (document == null || textSelection.getOffset() + textSelection.getLength() <= document.getLength())) {
SelectionChangedEvent syntheticEvent = new SelectionChangedEvent(selectionProvider, new TextSelection(textSelection.getOffset(), textSelection.getLength()));
((StructuredSelectionProvider) selectionProvider).handleSelectionChanged(syntheticEvent);
((StructuredSelectionProvider) selectionProvider).handlePostSelectionChanged(syntheticEvent);
}
else {
SelectionChangedEvent syntheticEvent = new SelectionChangedEvent(selectionProvider, new TextSelection(0, 0));
((StructuredSelectionProvider) selectionProvider).handleSelectionChanged(syntheticEvent);
((StructuredSelectionProvider) selectionProvider).handlePostSelectionChanged(syntheticEvent);
}
}
}