/*
  * @see org.eclipse.jface.text.source.SourceViewer#handleDispose()
  */
 @Override
 protected void handleDispose() {
   if (fBackspaceManager != null) {
     fBackspaceManager.uninstall();
     fBackspaceManager = null;
   }
   super.handleDispose();
 }
  /*
   * @see org.eclipse.jface.text.source.SourceViewer#createControl(org.eclipse.swt.widgets.Composite, int)
   */
  @Override
  protected void createControl(Composite parent, int styles) {

    // Use LEFT_TO_RIGHT unless otherwise specified.
    if ((styles & SWT.RIGHT_TO_LEFT) == 0 && (styles & SWT.LEFT_TO_RIGHT) == 0)
      styles |= SWT.LEFT_TO_RIGHT;

    final int baseLevel =
        (styles & SWT.RIGHT_TO_LEFT) != 0
            ? Bidi.DIRECTION_RIGHT_TO_LEFT
            : Bidi.DIRECTION_LEFT_TO_RIGHT;

    super.createControl(parent, styles);

    fBackspaceManager = new SmartBackspaceManager();
    fBackspaceManager.install(this);

    StyledText text = getTextWidget();
    text.addBidiSegmentListener(
        new BidiSegmentListener() {
          @Override
          public void lineGetSegments(BidiSegmentEvent event) {
            if (redraws()) {
              try {
                event.segments =
                    getBidiLineSegments(
                        getDocument(),
                        baseLevel,
                        widgetOffset2ModelOffset(event.lineOffset),
                        event.lineText);
              } catch (BadLocationException e) {
                // don't touch the segments
              }
            }
          }
        });
  }