* Returns the offset of the selected text in the given editor.
* @param editor the given editor.
* @return the offset of the selected text in the given editor, or -1 if there is no valid text information.
*/
public int selectionOffsetOf(IEditorPart editor) {
ISelectionProvider selectionProvider = ((ITextEditor) editor).getSelectionProvider();
ISelection selection = selectionProvider.getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
return textSelection.getOffset();
}
return -1;