Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 371924

Summary: [Cocoa] "Selection foreground color" preference not used
Product: [Eclipse Project] Platform Reporter: Adam Clark <adam.h.clark>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: bjoern.pollex, daniel_megert, markus.kell.r, remy.suen
Version: 3.7.1Keywords: triaged
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard: stalebug

Description Adam Clark CLA 2012-02-17 13:37:06 EST
Build Identifier: Version: Indigo Service Release 1 Build id: 20110916-0149 

The text editor does not seem to use the "Selection foreground color" preference.  The foreground color is set to "Foreground color" or by syntax coloring preferences.  This makes inverted selection color schemes impossible.

I've seen this in multiple packages -- verified with this build id as well:
Version: Indigo Service Release 1 Build id: 20110916-0149

Reproducible: Always

Steps to Reproduce:
1. Open Preferences > General > Editors > Text Editors
2. Click on "Selection foreground color" and set it to any other value (eg. bright red)
3. Click OK
4. Create a blank text file
5. Type anything and select the text

The foreground color remains unchanged.
Comment 1 Remy Suen CLA 2012-02-17 13:52:53 EST
Looks okay to me with I20120216-2200 on Windows 7.
Comment 2 Adam Clark CLA 2012-02-17 18:01:57 EST
I downloaded build I20120216-2200 and the problem persisted.

I wound up running the Eclipse debug, and tracked this down to the SWT library at
plugins/org.eclipse.swt.cocoa.macosx.x86_64_3.8.0.v3821b.jar

Starting at
org.eclipse.swt.graphics.TextLayout.java:484
it uses gc.data.foreground / gc.data.fg to set the color in the layoutManager, ignoring the passed-in selectionForeground.  Running in the debugger, executing

gc.setForeground(selectionForeground);
NSColor fg = gc.data.fg = NSColor.colorWithDeviceRed(selectionForeground.handle[0], selectionForeground.handle[1], selectionForeground.handle[2], selectionForeground.handle[3]);
fg.retain();

caused the correct foreground color to be used.

I don't know the system well enough to suggest a patch, though.
Comment 3 Bjoern Pollex CLA 2015-05-22 09:59:56 EDT
I am currently encountering this bug as well on Eclipse 4.2.2 running on Mac OS X 10.10.3. Is there any fix in sight?
Comment 4 Markus Keller CLA 2015-05-22 12:23:03 EDT
(In reply to Bjoern Pollex from comment #3)
> Is there any fix in sight?

Not really, and I'm not even sure there's actually anything to fix.

On Windows and GTK, a selection uses a different selection foreground color and overrides any non-default text color.

On Mac OS X, selections only change the background color but retain the foreground color of selected text. E.g. in TextEdit as well as in the Eclipse Java editor, colorized text keeps the color when selected. The "Selection foreground color" is not used. This is platform behavior that we don't plan to change.
Comment 5 Adam Clark CLA 2015-05-22 12:41:25 EDT
> This is platform behavior that we
> don't plan to change.

I don't see how this isn't a bug.  The user can set the "selection foreground color" in the preferences, but it's not used for the selection foreground color.  This seems like a clear case of the software failing its side of the contract.

And again, the "typical" selection scheme is inverted, eg. uses the normal foreground color as background and vice versa.  By inverting the background color but retaining the normal foreground color, this issue renders all selected text invisible.  In practice, this is a pretty big usability problem.
Comment 6 Markus Keller CLA 2015-05-22 13:10:20 EDT
Yes, the existence of a preference that doesn't do anything is a bug.

Unfortunately, SWT has to make a trade-off between adhering to platform conventions and offering a 100% portable API.

> the "typical" selection scheme is inverted

Not on the Mac. Here, the typical scheme is to have a selection background color that is close to the non-selection background color. For bright-on-dark color schemes, you have to choose a dark selection background color.
Comment 7 Bjoern Pollex CLA 2015-05-22 13:19:01 EDT
I've come across this because I have been trying to setup the Solarized color scheme in Eclipse. I have the same color scheme set up for both Emacs and PyCharm, both of which use inverted color when highlighting text, so it is apparently possible.

I fully understand that it may be too difficult to change though.
Comment 8 Lakshmi P Shanmugam CLA 2017-07-03 01:14:56 EDT
Bug triaged, visit https://wiki.eclipse.org/SWT/Devel/Triage for more information.
Comment 9 Eclipse Genie CLA 2020-06-18 04:37:04 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.