Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 135345 - [Text] Selecting text in WSIWIG example makes text disappear
Summary: [Text] Selecting text in WSIWIG example makes text disappear
Status: RESOLVED FIXED
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy GEF (MVC) (show other bugs)
Version: 3.2   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7.1 (Indigo) M5   Edit
Assignee: Alexander Nyßen CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 332872
Blocks:
  Show dependency tree
 
Reported: 2006-04-06 14:29 EDT by Steven R. Shaw CLA
Modified: 2011-02-02 18:24 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven R. Shaw CLA 2006-04-06 14:29:13 EDT
Mac only:
- Create new project
- Create new text WSIWIG example.
- Select some text within the example.

Result:
- text disappears
Comment 1 Randy Hudson CLA 2006-04-06 15:25:07 EDT
We will have to add platform specific code in TextFlow. Also, the default drag feedback uses XOR, as does the Marquee Rectangle.
Comment 2 Eric Wasserman CLA 2006-09-29 17:54:48 EDT
If you change TextFlow to this it works  pretty well:

  /**
   * @see InlineFlow#paintSelection(org.eclipse.draw2d.Graphics)
   */
  protected void paintSelection(Graphics graphics) {
    if (selectionStart == -1)
      return;

    if (isXORCapable) {
      graphics.setXORMode(true);
      graphics.setBackgroundColor(ColorConstants.white);
    } else {
      int selectionAlpha = 140;
      graphics.setAlpha(selectionAlpha);
      Display display = Display.getCurrent();
      Color selectionColor = (display != null) ? display.getSystemColor(SWT.COLOR_LIST_SELECTION)
          : ColorConstants.menuBackgroundSelected;
      graphics.setBackgroundColor(selectionColor);
    }

    TextFragmentBox frag;
    for (int i = 0; i < fragments.size(); i++) {
[...same as current...]
    }
  }

It certainly would be preferable to have this over selection erasing the selected text as it does now.

Ultimately it would be preferable to have TextFlow.paintText always use Graphics.drawTextLayout(TextLayout, int, int, int, int, Color, Color) to draw the text with selection. Though this doesn't highlight the border drawing its not clear this is even desireable. Am I missing something?
Comment 3 Eric Wasserman CLA 2006-09-29 21:26:29 EDT
Instead of using XOR for text selection highlighting having the TextLayout render the highlighted text works great. This works quite well:

1) add to TextFlow:

  private void paintTextWithSelection(Graphics g, String draw, int x, int y, int startSelection, int endSelection) {
    TextLayout tl = FlowUtilities.getTextLayout();
    if (isMirrored())
      tl.setOrientation(SWT.RIGHT_TO_LEFT);
    tl.setFont(g.getFont());
    tl.setText(draw);
    Color selectionForeground = ColorConstants.menuForegroundSelected;
    Color selectionBackground = ColorConstants.menuBackgroundSelected;
    g.drawTextLayout(tl, x, y, startSelection, endSelection, selectionForeground, selectionBackground);
  }


2) in TextFlow.paintFigure() do this instead of paintText:


        int selStart = -1, selEnd = -1;
        if (selectionStart != -1 && selectionStart < frag.offset + frag.length && frag.offset <= selectionEnd) {
          selStart = Math.max(selectionStart - frag.offset, 0);
          selEnd = Math.min(selectionEnd - frag.offset, frag.offset + frag.length) - 1;
          selEnd += (selEnd < 0) ? 0 : getBidiPrefixLength(frag, i);
        }
        paintTextWithSelection(g, draw,
					frag.getX(),
					frag.getBaseline() - getAscent(),
					selStart, selEnd);
Comment 4 Alexander Nyßen CLA 2011-01-06 13:53:05 EST
Verified that with Eclipse 3.6.1 this no longer occurs on Mac OS X Carbon (10.4.11, Java 5) and - with the now implemented XOR functionality on Mac Cocoa - that with Eclipse 3.7 N20101218 this no longer occurs on Mac OS X Cocoa as well. Resolving as fixed in 3.7.
Comment 5 Randy Hudson CLA 2011-01-06 15:03:10 EST
(In reply to comment #4)
> Verified that with Eclipse 3.6.1 this no longer occurs on Mac OS X Carbon
> (10.4.11, Java 5) and - with the now implemented XOR functionality on Mac Cocoa
> - that with Eclipse 3.7 N20101218 this no longer occurs on Mac OS X Cocoa as
> well. Resolving as fixed in 3.7.

Since XOR works on the Mac now, has SWT undeprecated that API?
Comment 6 Alexander Nyßen CLA 2011-01-06 15:14:30 EST
(In reply to comment #5)
> (In reply to comment #4)
> > Verified that with Eclipse 3.6.1 this no longer occurs on Mac OS X Carbon
> > (10.4.11, Java 5) and - with the now implemented XOR functionality on Mac Cocoa
> > - that with Eclipse 3.7 N20101218 this no longer occurs on Mac OS X Cocoa as
> > well. Resolving as fixed in 3.7.
> 
> Since XOR works on the Mac now, has SWT undeprecated that API?

From Scott's comment to 332872 I cannot infer that this has officially been done yet. However, he implemented the respective functionality for 3.7, so maybe it would be worth issuing a request for this.
Comment 7 Alexander Nyßen CLA 2011-02-02 18:24:57 EST
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > Verified that with Eclipse 3.6.1 this no longer occurs on Mac OS X Carbon
> > > (10.4.11, Java 5) and - with the now implemented XOR functionality on Mac Cocoa
> > > - that with Eclipse 3.7 N20101218 this no longer occurs on Mac OS X Cocoa as
> > > well. Resolving as fixed in 3.7.
> > 
> > Since XOR works on the Mac now, has SWT undeprecated that API?
> 
> From Scott's comment to 332872 I cannot infer that this has officially been
> done yet. However, he implemented the respective functionality for 3.7, so
> maybe it would be worth issuing a request for this.

FYI: bug #333391 has been raised to handle the un-deprecation of GC#setXorMode().