Skip to content

Commit

Permalink
Always use focus selection color for code completion proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Hermann authored and BeckerWdf committed May 13, 2024
1 parent 3d38c23 commit 1d11421
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static StyleRange[] getStyledRanges(TableItem item, int column) {
return (StyleRange[])item.getData(STYLED_RANGES_KEY + column);
}

private TableOwnerDrawSupport(Table table) {
protected 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
Expand Up @@ -57,6 +57,7 @@
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerExtension;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.contentassist.CompletionTableDrawSupport;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
Expand Down Expand Up @@ -269,7 +270,7 @@ private void createProposalSelector() {

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

fProposalTable.setLocation(0, 0);
if (fAdditionalInfoController != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void createProposalSelector() {

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

fProposalTable.setLocation(0, 0);
if (fAdditionalInfoController != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.eclipse.jface.text.contentassist;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Table;

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

/**
* When a completion table (for example for code completion) is requested by the user, the user
* needs to be able to continue typing in the linked text control. In such cases, the focus is not
* on the completion table. To ensure the selected code completion proposal always displays in the
* correct color, even if the completion table is not focused, the non-focused colors are overridden
* with the focus colors.
*/
public class CompletionTableDrawSupport extends TableOwnerDrawSupport {

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

private CompletionTableDrawSupport(Table table) {
super(table);
}

@Override
protected Color getSelectedRowBackgroundColorNoFocus() {
return super.getSelectedRowBackgroundColor();
}

@Override
protected Color getSelectedRowForegroundColorNoFocus() {
return super.getSelectedRowForegroundColor();
}

}

0 comments on commit 1d11421

Please sign in to comment.