title: Caret position of Eclipse text editor
body: <p>I'm writing a little plugin to move the caret position of an Eclipse text editor to the other side of a selected block. Problem is that I don't find a nice way to discover whether the selection is left-to-right or right-to-left.</p>
  
  <p>I understand there are these alternatives:</p>
  
  <ul>
  <li>Use a CarretListener in some way. It seems unnecessary and I don't want to.</li>
  <li>Get hold of the underlaying <code>StyledText</code> and compare selection with the caret position. Seems to break abstraction because I have to know how the editor is implemented. Another disadvantage is that you would have to use <code>widgetOffset2ModelOffset</code> methods on the text viewer to adjust positions.</li>
  </ul>
  
  <p>Can't I get the caret position from my <code>ITextEditor</code> or <code>ISelectionProvider</code> or something?</p>
  
  <p>Here is my code:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class SwapCursorSelectionHandler extends AbstractHandler {
      public Object execute( ExecutionEvent event )
      {
          ITextEditor editor;
          try {
              editor = (ITextEditor) HandlerUtil.getActivePartChecked( event );
          } catch ( ExecutionException exc ) {
              throw new RuntimeException( exc );
          }
  
          ITextSelection sel = (ITextSelection) editor.getSelectionProvider().getSelection();
  
          // How to find out if sel is left-to-right or right-to-left?!
  
          editor.selectAndReveal( ... );
  
          return null;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Update: There doesn't seem to be a way to do this without using the <code>StyledText</code>. I think this is weird and I considers placing a bug report suggesting that selection direction information should be added to <code>ITextSelection</code>. Before I do this it would be interesting to get the opinion on people here at SO about this proposal.</p>