Copied from org.eclipse.ui.texteditor.