Skip to content

Commit 9972b7b

Browse files
Draw completion proposals always as focused
When opening the completion proposals via the keyboard, the focus will stay in the editor to be able to accept further user input. This is causing the completion proposal to be drawn in non focus colors. This colors can lead to UX problems, especially in dark theme. With this fix, the completion proposals are always drawn in focused colors. Fixes #1688
1 parent 35844b5 commit 9972b7b

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-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
@@ -70,7 +70,7 @@ private static StyleRange[] getStyledRanges(TableItem item, int column) {
7070
return (StyleRange[])item.getData(STYLED_RANGES_KEY + column);
7171
}
7272

73-
private TableOwnerDrawSupport(Table table) {
73+
public TableOwnerDrawSupport(Table table) {
7474
int orientation= table.getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
7575
fSharedLayout= new TextLayout(table.getDisplay());
7676
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.CompletionProposalDrawSupport;
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+
CompletionProposalDrawSupport.install(fProposalTable);
273274

274275
fProposalTable.setLocation(0, 0);
275276
if (fAdditionalInfoController != null)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 SAP SE.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* SAP SE - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jface.text.contentassist;
15+
16+
import org.eclipse.swt.SWT;
17+
import org.eclipse.swt.graphics.Color;
18+
import org.eclipse.swt.widgets.Event;
19+
import org.eclipse.swt.widgets.Listener;
20+
import org.eclipse.swt.widgets.Table;
21+
22+
import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
23+
24+
/**
25+
* Provides custom drawing support for completion proposals. This class ensures that completion
26+
* proposals are always rendered with a focused appearance.
27+
*
28+
* <p>
29+
* This drawing behavior addresses the particular situation where the code completion is triggered
30+
* via keyboard shortcut, leaving the editor focused. In such cases, without this custom drawing
31+
* support, the completion proposal would appear unfocused, leading to a suboptimal coloring.
32+
* </p>
33+
*/
34+
public class CompletionProposalDrawSupport implements Listener {
35+
36+
private TableOwnerDrawSupport fTableOwnerDrawSupport;
37+
38+
private CompletionProposalDrawSupport(Table table) {
39+
fTableOwnerDrawSupport= new TableOwnerDrawSupport(table);
40+
}
41+
42+
public static void install(Table table) {
43+
CompletionProposalDrawSupport listener= new CompletionProposalDrawSupport(table);
44+
table.addListener(SWT.Dispose, listener);
45+
table.addListener(SWT.MeasureItem, listener);
46+
table.addListener(SWT.EraseItem, listener);
47+
table.addListener(SWT.PaintItem, listener);
48+
}
49+
50+
@Override
51+
public void handleEvent(Event event) {
52+
Color background= event.item.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
53+
Color forground= event.item.getDisplay().getSystemColor(SWT.COLOR_WHITE);
54+
event.gc.setBackground(background);
55+
event.gc.setForeground(forground);
56+
fTableOwnerDrawSupport.handleEvent(event);
57+
}
58+
59+
}

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+
CompletionProposalDrawSupport.install(fProposalTable);
617617

618618
fProposalTable.setLocation(0, 0);
619619
if (fAdditionalInfoController != null)

0 commit comments

Comments
 (0)