Skip to content

Draw completion proposals always as focused #2793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static StyleRange[] getStyledRanges(TableItem item, int column) {
return (StyleRange[])item.getData(STYLED_RANGES_KEY + column);
}

private TableOwnerDrawSupport(Table table) {
public TableOwnerDrawSupport(Table table) {
int orientation= table.getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
fSharedLayout= new TextLayout(table.getDisplay());
fSharedLayout.setOrientation(orientation);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2025 SAP SE.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.internal.text.contentassist;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;

import org.eclipse.jface.internal.text.TableOwnerDrawSupport;

/**
* Provides custom drawing support for completion proposals. This class ensures that completion
* proposals are always rendered with a focused appearance.
*
* <p>
* This drawing behavior addresses the particular situation where the code completion is triggered
* via keyboard shortcut, leaving the editor focused. In such cases, without this custom drawing
* support, the completion proposal would appear unfocused, leading to a suboptimal coloring.
* </p>
*/
public class CompletionProposalDrawSupport implements Listener {

private TableOwnerDrawSupport fTableOwnerDrawSupport;

private CompletionProposalDrawSupport(Table table) {
fTableOwnerDrawSupport= new TableOwnerDrawSupport(table);
}

public static void install(Table table) {
CompletionProposalDrawSupport listener= new CompletionProposalDrawSupport(table);
table.addListener(SWT.Dispose, listener);
table.addListener(SWT.MeasureItem, listener);
table.addListener(SWT.EraseItem, listener);
table.addListener(SWT.PaintItem, listener);
}

@Override
public void handleEvent(Event event) {
if (event.widget instanceof Control control && !control.isFocusControl() && (event.type == SWT.EraseItem || event.type == SWT.PaintItem) && event.gc != null) {
Color background= event.widget.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
Color foreground= event.widget.getDisplay().getSystemColor(SWT.COLOR_WHITE);
event.gc.setBackground(background);
event.gc.setForeground(foreground);
}

fTableOwnerDrawSupport.handleEvent(event);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.swt.widgets.TableItem;

import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
import org.eclipse.jface.internal.text.contentassist.CompletionProposalDrawSupport;
import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceColors;
Expand Down Expand Up @@ -269,7 +270,7 @@ private void createProposalSelector() {

fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled();
if (fIsColoredLabelsSupportEnabled)
TableOwnerDrawSupport.install(fProposalTable);
CompletionProposalDrawSupport.install(fProposalTable);

fProposalTable.setLocation(0, 0);
if (fAdditionalInfoController != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
import org.eclipse.jface.internal.text.InformationControlReplacer;
import org.eclipse.jface.internal.text.TableOwnerDrawSupport;
import org.eclipse.jface.internal.text.contentassist.CompletionProposalDrawSupport;
import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.resource.JFaceResources;
Expand Down Expand Up @@ -613,7 +614,7 @@ void createProposalSelector() {

fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled();
if (fIsColoredLabelsSupportEnabled)
TableOwnerDrawSupport.install(fProposalTable);
CompletionProposalDrawSupport.install(fProposalTable);

fProposalTable.setLocation(0, 0);
if (fAdditionalInfoController != null)
Expand Down
Loading