Skip to content

Commit 9b5ce3d

Browse files
Christopher-Hermannfedejeanne
authored andcommitted
Always use focus selection color for code completion proposals
Fixes eclipse-platform#1688
1 parent 3b5769b commit 9b5ce3d

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/TableOwnerDrawSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static StyleRange[] getStyledRanges(TableItem item, int column) {
7373
return (StyleRange[])item.getData(STYLED_RANGES_KEY + column);
7474
}
7575

76-
private TableOwnerDrawSupport(Table table) {
76+
protected TableOwnerDrawSupport(Table table) {
7777
int orientation= table.getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
7878
fSharedLayout= new TextLayout(table.getDisplay());
7979
fSharedLayout.setOrientation(orientation);

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.eclipse.jface.text.ITextViewer;
5858
import org.eclipse.jface.text.ITextViewerExtension;
5959
import org.eclipse.jface.text.TextUtilities;
60+
import org.eclipse.jface.text.contentassist.CompletionTableDrawSupport;
6061
import org.eclipse.jface.text.contentassist.ICompletionProposal;
6162
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
6263
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
@@ -269,7 +270,7 @@ private void createProposalSelector() {
269270

270271
fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled();
271272
if (fIsColoredLabelsSupportEnabled)
272-
TableOwnerDrawSupport.install(fProposalTable);
273+
CompletionTableDrawSupport.install(fProposalTable);
273274

274275
fProposalTable.setLocation(0, 0);
275276
if (fAdditionalInfoController != null)

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void createProposalSelector() {
613613

614614
fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled();
615615
if (fIsColoredLabelsSupportEnabled)
616-
TableOwnerDrawSupport.install(fProposalTable);
616+
CompletionTableDrawSupport.install(fProposalTable);
617617

618618
fProposalTable.setLocation(0, 0);
619619
if (fAdditionalInfoController != null)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.eclipse.jface.text.contentassist;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.graphics.Color;
5+
import org.eclipse.swt.widgets.Table;
6+
7+
import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
8+
9+
/**
10+
* When a completion table (for example for code completion) is requested by the user, the user
11+
* needs to be able to continue typing in the linked text control. In such cases, the focus is not
12+
* on the completion table. To ensure the selected code completion proposal always displays in the
13+
* correct color, even if the completion table is not focused, the non-focused colors are overridden
14+
* with the focus colors.
15+
*/
16+
public class CompletionTableDrawSupport extends TableOwnerDrawSupport {
17+
18+
public static void install(Table table) {
19+
TableOwnerDrawSupport listener= new CompletionTableDrawSupport(table);
20+
table.addListener(SWT.Dispose, listener);
21+
table.addListener(SWT.MeasureItem, listener);
22+
table.addListener(SWT.EraseItem, listener);
23+
table.addListener(SWT.PaintItem, listener);
24+
}
25+
26+
private CompletionTableDrawSupport(Table table) {
27+
super(table);
28+
}
29+
30+
@Override
31+
protected Color getSelectedRowBackgroundColorNoFocus() {
32+
return super.getSelectedRowBackgroundColor();
33+
}
34+
35+
@Override
36+
protected Color getSelectedRowForegroundColorNoFocus() {
37+
return super.getSelectedRowForegroundColor();
38+
}
39+
40+
}

0 commit comments

Comments
 (0)