if (newSelectionRegion != null) {
SelectionHistory history = (SelectionHistory) editor.getAdapter(SelectionHistory.class);
if (history != null) {
history.remember(new Region(textSelection.getOffset(), textSelection.getLength()));
try {
history.ignoreSelectionChanges();
textEditor.selectAndReveal(newSelectionRegion.getOffset(), newSelectionRegion.getLength());
}
finally {
history.listenToSelectionChanges();
}