diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/TableOwnerDrawSupport.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/TableOwnerDrawSupport.java index a3052c84d42..d044442ce97 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/TableOwnerDrawSupport.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/TableOwnerDrawSupport.java @@ -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); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/contentassist/CompletionProposalDrawSupport.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/contentassist/CompletionProposalDrawSupport.java new file mode 100644 index 00000000000..eb7b9369cd7 --- /dev/null +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/contentassist/CompletionProposalDrawSupport.java @@ -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. + * + *

+ * 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. + *

+ */ +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); + } + +} diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java index 6ca009a07d7..5e941c552ba 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java @@ -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; @@ -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) diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java index f426f8b7ce8..f666903ac9c 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java @@ -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; @@ -613,7 +614,7 @@ void createProposalSelector() { fIsColoredLabelsSupportEnabled= fContentAssistant.isColoredLabelsSupportEnabled(); if (fIsColoredLabelsSupportEnabled) - TableOwnerDrawSupport.install(fProposalTable); + CompletionProposalDrawSupport.install(fProposalTable); fProposalTable.setLocation(0, 0); if (fAdditionalInfoController != null)