Skip to content

Commit 51a7e93

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 a879598 commit 51a7e93

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-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);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.internal.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+
if (event.type == SWT.EraseItem && event.widget != null && event.gc != null) {
53+
Color background= event.widget.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
54+
Color forground= event.widget.getDisplay().getSystemColor(SWT.COLOR_WHITE);
55+
event.gc.setBackground(background);
56+
event.gc.setForeground(forground);
57+
}
58+
fTableOwnerDrawSupport.handleEvent(event);
59+
}
60+
61+
}

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
@@ -40,6 +40,7 @@
4040
import org.eclipse.swt.widgets.TableItem;
4141

4242
import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
43+
import org.eclipse.jface.internal.text.contentassist.CompletionProposalDrawSupport;
4344
import org.eclipse.jface.preference.JFacePreferences;
4445
import org.eclipse.jface.resource.ColorRegistry;
4546
import org.eclipse.jface.resource.JFaceColors;
@@ -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)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
8080
import org.eclipse.jface.internal.text.InformationControlReplacer;
8181
import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
82+
import org.eclipse.jface.internal.text.contentassist.CompletionProposalDrawSupport;
8283
import org.eclipse.jface.preference.JFacePreferences;
8384
import org.eclipse.jface.resource.JFaceColors;
8485
import org.eclipse.jface.resource.JFaceResources;
@@ -613,7 +614,7 @@ void createProposalSelector() {
613614

614615
fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled();
615616
if (fIsColoredLabelsSupportEnabled)
616-
TableOwnerDrawSupport.install(fProposalTable);
617+
CompletionProposalDrawSupport.install(fProposalTable);
617618

618619
fProposalTable.setLocation(0, 0);
619620
if (fAdditionalInfoController != null)

0 commit comments

Comments
 (0)