Skip to content

Commit d87265e

Browse files
authored
fix: button colors + invisible cursor (#352)
* fix: button colors + double cursor * fix: color fallbacks
1 parent e9c85d2 commit d87265e

File tree

3 files changed

+86
-83
lines changed

3 files changed

+86
-83
lines changed

plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java

Lines changed: 85 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public class BaseHtmlProvider {
2525
private final Map<String, String> colorCache = new HashMap<>();
2626
private String nonce = "";
2727

28-
// Suffix used to neutralize VSCode CSS variable fallbacks (e.g., "var(--vscode-foo, fallback)")
29-
// We replace "var(--vscode-foo," with "value; --unused:" so the fallback becomes a no-op property
30-
private static final String VSCODE_VAR_SUFFIX = "; --unused:";
3128

3229
// Eclipse theme color keys
3330
private static final String THEME_INACTIVE_TAB_BG = "org.eclipse.ui.workbench.INACTIVE_TAB_BG_START";
@@ -38,6 +35,7 @@ public class BaseHtmlProvider {
3835
private static final String THEME_ACTIVE_TAB_BG_END = "org.eclipse.ui.workbench.ACTIVE_TAB_BG_END";
3936
private static final String THEME_ACTIVE_HYPERLINK = "ACTIVE_HYPERLINK_COLOR";
4037
private static final String THEME_DARK_BACKGROUND = "org.eclipse.ui.workbench.DARK_BACKGROUND";
38+
private static final String THEME_HYPERLINK_COLOR = "org.eclipse.ui.editors.hyperlinkColor";
4139

4240
private static final String CSS_VAR_DEFAULT_FONT = "var(--default-font)";
4341
private static final String CSS_VAR_MAIN_FONT_SIZE = "var(--main-font-size)";
@@ -56,30 +54,29 @@ public class BaseHtmlProvider {
5654
private static final String CSS_VAR_INPUT_BACKGROUND_COLOR = "var(--input-background-color)";
5755
private static final String CSS_VAR_FOCUS_COLOR = "var(--focus-color)";
5856

59-
private static final String VSCODE_VAR_FONT_FAMILY_PREFIX = "var(--vscode-font-family,";
60-
private static final String VSCODE_VAR_EDITOR_FONT_FAMILY_PREFIX = "var(--vscode-editor-font-family,";
61-
private static final String VSCODE_VAR_FONT_SIZE_PREFIX = "var(--vscode-font-size,";
62-
private static final String VSCODE_VAR_EDITOR_BACKGROUND_PREFIX = "var(--vscode-editor-background,";
63-
private static final String VSCODE_VAR_FOREGROUND_PREFIX = "var(--vscode-foreground,";
64-
private static final String VSCODE_VAR_INPUT_FOREGROUND_PREFIX = "var(--vscode-input-foreground,";
65-
private static final String VSCODE_VAR_EDITOR_FOREGROUND_PREFIX = "var(--vscode-editor-foreground,";
66-
private static final String VSCODE_VAR_DISABLED_FOREGROUND_PREFIX = "var(--vscode-disabledForeground,";
67-
private static final String VSCODE_VAR_ERROR_FOREGROUND_PREFIX = "var(--vscode-errorForeground,";
68-
private static final String VSCODE_VAR_INPUT_BACKGROUND_PREFIX = "var(--vscode-input-background,";
69-
private static final String VSCODE_VAR_EDITOR_INACTIVE_SELECTION_BG_PREFIX = "var(--vscode-editor-inactiveSelectionBackground,";
70-
private static final String VSCODE_VAR_BUTTON_BACKGROUND_PREFIX = "var(--vscode-button-background,";
71-
private static final String VSCODE_VAR_BUTTON_FOREGROUND_PREFIX = "var(--vscode-button-foreground,";
72-
private static final String VSCODE_VAR_BUTTON_HOVER_BG_PREFIX = "var(--vscode-button-hoverBackground,";
73-
private static final String VSCODE_VAR_BUTTON_SECONDARY_BG_PREFIX = "var(--vscode-button-secondaryBackground,";
74-
private static final String VSCODE_VAR_BUTTON_SECONDARY_FOREGROUND_PREFIX = "var(--vscode-button-secondaryForeground,";
75-
private static final String VSCODE_VAR_BUTTON_SECONDARY_HOVER_BG_PREFIX = "var(--vscode-button-secondaryHoverBackground,";
76-
private static final String VSCODE_VAR_LIST_HOVER_BG_PREFIX = "var(--vscode-list-hoverBackground,";
77-
private static final String VSCODE_VAR_INPUT_BORDER_PREFIX = "var(--vscode-input-border,";
78-
private static final String VSCODE_VAR_PANEL_BORDER_PREFIX = "var(--vscode-panel-border,";
79-
private static final String VSCODE_VAR_FOCUS_BORDER_PREFIX = "var(--vscode-focusBorder,";
80-
private static final String VSCODE_VAR_SCROLLBAR_SLIDER_BG_PREFIX = "var(--vscode-scrollbarSlider-background,";
81-
private static final String VSCODE_VAR_SCROLLBAR_SLIDER_HOVER_BG_PREFIX = "var(--vscode-scrollbarSlider-hoverBackground,";
82-
private static final String VSCODE_VAR_SCROLLBAR_SLIDER_ACTIVE_BG_PREFIX = "var(--vscode-scrollbarSlider-activeBackground,";
57+
// CSS variables used in LS-served HTML (styles.css from snyk-ls)
58+
private static final String CSS_VAR_LS_BACKGROUND_COLOR = "var(--background-color)";
59+
private static final String CSS_VAR_LS_TEXT_COLOR = "var(--text-color)";
60+
private static final String CSS_VAR_LS_INPUT_FOREGROUND = "var(--input-foreground)";
61+
private static final String CSS_VAR_LS_EDITOR_FOREGROUND = "var(--editor-foreground)";
62+
private static final String CSS_VAR_LS_DISABLED_FOREGROUND = "var(--disabled-foreground)";
63+
private static final String CSS_VAR_LS_ERROR_FOREGROUND = "var(--error-foreground)";
64+
private static final String CSS_VAR_LS_INPUT_BACKGROUND = "var(--input-background)";
65+
private static final String CSS_VAR_LS_SECTION_BACKGROUND = "var(--section-background)";
66+
private static final String CSS_VAR_LS_BUTTON_BACKGROUND_COLOR = "var(--button-background-color)";
67+
private static final String CSS_VAR_LS_BUTTON_FOREGROUND = "var(--button-foreground)";
68+
private static final String CSS_VAR_LS_BUTTON_HOVER_BACKGROUND = "var(--button-hover-background)";
69+
private static final String CSS_VAR_LS_BUTTON_SECONDARY_BACKGROUND = "var(--button-secondary-background)";
70+
private static final String CSS_VAR_LS_BUTTON_SECONDARY_FOREGROUND = "var(--button-secondary-foreground)";
71+
private static final String CSS_VAR_LS_BUTTON_SECONDARY_HOVER_BACKGROUND = "var(--button-secondary-hover-background)";
72+
private static final String CSS_VAR_LS_LIST_HOVER_BACKGROUND = "var(--list-hover-background)";
73+
private static final String CSS_VAR_LS_INPUT_BORDER = "var(--input-border)";
74+
private static final String CSS_VAR_LS_BORDER_COLOR = "var(--border-color)";
75+
private static final String CSS_VAR_LS_FOCUS_BORDER = "var(--focus-border)";
76+
private static final String CSS_VAR_LS_SCROLLBAR_BACKGROUND = "var(--scrollbar-background)";
77+
private static final String CSS_VAR_LS_SCROLLBAR_HOVER_BACKGROUND = "var(--scrollbar-hover-background)";
78+
private static final String CSS_VAR_LS_SCROLLBAR_ACTIVE_BACKGROUND = "var(--scrollbar-active-background)";
79+
8380

8481
// Default fallback colors
8582
private static final String DEFAULT_SECTION_BG_COLOR = "#F0F0F0";
@@ -204,41 +201,44 @@ public String replaceCssVariables(String html, boolean useRelativeFontSize) {
204201
getColorAsHex(THEME_INACTIVE_TAB_BG, DEFAULT_SECTION_BG_COLOR));
205202
htmlStyled = htmlStyled.replace(CSS_VAR_FOCUS_COLOR, getColorAsHex(THEME_ACTIVE_TAB_KEYLINE, DEFAULT_BORDER_COLOR));
206203

207-
// Replace VSCode CSS variables used in LS-served HTML (settings page)
204+
// Replace CSS variables used in LS-served HTML (settings page)
205+
// Get Eclipse theme colors
208206
String textColor = getColorAsHex(THEME_ACTIVE_TAB_SELECTED_TEXT, "#000000");
209207
String bgColor = getColorAsHex(THEME_ACTIVE_TAB_BG_END, DEFAULT_WHITE_COLOR);
210208
String inputBgColor = getColorAsHex(THEME_INACTIVE_TAB_BG, DEFAULT_SECTION_BG_COLOR);
211209
String borderColor = getColorAsHex(THEME_ACTIVE_TAB_KEYLINE, DEFAULT_BORDER_COLOR);
212210
String focusColor = getColorAsHex(THEME_ACTIVE_TAB_KEYLINE, DEFAULT_BORDER_COLOR);
213-
String buttonBgColor = getColorAsHex(THEME_INACTIVE_TAB_BG, DEFAULT_SECTION_BG_COLOR);
214-
String buttonFgColor = getColorAsHex(THEME_ACTIVE_TAB_TEXT, "#000000");
215-
String buttonHoverBgColor = getColorAsHex(THEME_ACTIVE_NOFOCUS_TAB_BG, "#E0E0E0");
216211
String sectionBgColor = getColorAsHex(THEME_INACTIVE_TAB_BG, DEFAULT_SECTION_BG_COLOR);
217212

218-
htmlStyled = htmlStyled.replace(VSCODE_VAR_FONT_FAMILY_PREFIX, textColor + VSCODE_VAR_SUFFIX);
219-
htmlStyled = htmlStyled.replace(VSCODE_VAR_EDITOR_FONT_FAMILY_PREFIX, textColor + VSCODE_VAR_SUFFIX);
220-
htmlStyled = htmlStyled.replace(VSCODE_VAR_FONT_SIZE_PREFIX, "13px" + VSCODE_VAR_SUFFIX);
221-
htmlStyled = htmlStyled.replace(VSCODE_VAR_EDITOR_BACKGROUND_PREFIX, bgColor + VSCODE_VAR_SUFFIX);
222-
htmlStyled = htmlStyled.replace(VSCODE_VAR_FOREGROUND_PREFIX, textColor + VSCODE_VAR_SUFFIX);
223-
htmlStyled = htmlStyled.replace(VSCODE_VAR_INPUT_FOREGROUND_PREFIX, textColor + VSCODE_VAR_SUFFIX);
224-
htmlStyled = htmlStyled.replace(VSCODE_VAR_EDITOR_FOREGROUND_PREFIX, textColor + VSCODE_VAR_SUFFIX);
225-
htmlStyled = htmlStyled.replace(VSCODE_VAR_DISABLED_FOREGROUND_PREFIX, "#808080" + VSCODE_VAR_SUFFIX);
226-
htmlStyled = htmlStyled.replace(VSCODE_VAR_ERROR_FOREGROUND_PREFIX, "#f48771" + VSCODE_VAR_SUFFIX);
227-
htmlStyled = htmlStyled.replace(VSCODE_VAR_INPUT_BACKGROUND_PREFIX, inputBgColor + VSCODE_VAR_SUFFIX);
228-
htmlStyled = htmlStyled.replace(VSCODE_VAR_EDITOR_INACTIVE_SELECTION_BG_PREFIX, sectionBgColor + VSCODE_VAR_SUFFIX);
229-
htmlStyled = htmlStyled.replace(VSCODE_VAR_BUTTON_BACKGROUND_PREFIX, buttonBgColor + VSCODE_VAR_SUFFIX);
230-
htmlStyled = htmlStyled.replace(VSCODE_VAR_BUTTON_FOREGROUND_PREFIX, buttonFgColor + VSCODE_VAR_SUFFIX);
231-
htmlStyled = htmlStyled.replace(VSCODE_VAR_BUTTON_HOVER_BG_PREFIX, buttonHoverBgColor + VSCODE_VAR_SUFFIX);
232-
htmlStyled = htmlStyled.replace(VSCODE_VAR_BUTTON_SECONDARY_BG_PREFIX, sectionBgColor + VSCODE_VAR_SUFFIX);
233-
htmlStyled = htmlStyled.replace(VSCODE_VAR_BUTTON_SECONDARY_FOREGROUND_PREFIX, textColor + VSCODE_VAR_SUFFIX);
234-
htmlStyled = htmlStyled.replace(VSCODE_VAR_BUTTON_SECONDARY_HOVER_BG_PREFIX, inputBgColor + VSCODE_VAR_SUFFIX);
235-
htmlStyled = htmlStyled.replace(VSCODE_VAR_LIST_HOVER_BG_PREFIX, sectionBgColor + VSCODE_VAR_SUFFIX);
236-
htmlStyled = htmlStyled.replace(VSCODE_VAR_INPUT_BORDER_PREFIX, borderColor + VSCODE_VAR_SUFFIX);
237-
htmlStyled = htmlStyled.replace(VSCODE_VAR_PANEL_BORDER_PREFIX, borderColor + VSCODE_VAR_SUFFIX);
238-
htmlStyled = htmlStyled.replace(VSCODE_VAR_FOCUS_BORDER_PREFIX, focusColor + VSCODE_VAR_SUFFIX);
239-
htmlStyled = htmlStyled.replace(VSCODE_VAR_SCROLLBAR_SLIDER_BG_PREFIX, inputBgColor + VSCODE_VAR_SUFFIX);
240-
htmlStyled = htmlStyled.replace(VSCODE_VAR_SCROLLBAR_SLIDER_HOVER_BG_PREFIX, inputBgColor + VSCODE_VAR_SUFFIX);
241-
htmlStyled = htmlStyled.replace(VSCODE_VAR_SCROLLBAR_SLIDER_ACTIVE_BG_PREFIX, inputBgColor + VSCODE_VAR_SUFFIX);
213+
// Button colors: Use Eclipse hyperlink color for primary, inactive tab for secondary
214+
String buttonBgColor = getColorAsHex(THEME_HYPERLINK_COLOR, "#0000FF");
215+
String buttonFgColor = DEFAULT_WHITE_COLOR;
216+
String buttonHoverBgColor = adjustBrightness(buttonBgColor, 1.15f);
217+
String buttonSecondaryBgColor = getColorAsHex(THEME_INACTIVE_TAB_BG, DEFAULT_SECTION_BG_COLOR);
218+
String buttonSecondaryHoverBgColor = adjustBrightness(buttonSecondaryBgColor, 1.15f);
219+
220+
// Replace LS CSS variables with Eclipse theme values
221+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BACKGROUND_COLOR, bgColor);
222+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_TEXT_COLOR, textColor);
223+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_INPUT_FOREGROUND, textColor);
224+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_EDITOR_FOREGROUND, textColor);
225+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_DISABLED_FOREGROUND, "#808080");
226+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_ERROR_FOREGROUND, "#f48771");
227+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_INPUT_BACKGROUND, inputBgColor);
228+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_SECTION_BACKGROUND, sectionBgColor);
229+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BUTTON_BACKGROUND_COLOR, buttonBgColor);
230+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BUTTON_FOREGROUND, buttonFgColor);
231+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BUTTON_HOVER_BACKGROUND, buttonHoverBgColor);
232+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BUTTON_SECONDARY_BACKGROUND, buttonSecondaryBgColor);
233+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BUTTON_SECONDARY_FOREGROUND, textColor);
234+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BUTTON_SECONDARY_HOVER_BACKGROUND, buttonSecondaryHoverBgColor);
235+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_LIST_HOVER_BACKGROUND, "rgba(255, 255, 255, 0.05)");
236+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_INPUT_BORDER, borderColor);
237+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_BORDER_COLOR, borderColor);
238+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_FOCUS_BORDER, focusColor);
239+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_SCROLLBAR_BACKGROUND, inputBgColor);
240+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_SCROLLBAR_HOVER_BACKGROUND, adjustBrightness(inputBgColor, 1.1f));
241+
htmlStyled = htmlStyled.replace(CSS_VAR_LS_SCROLLBAR_ACTIVE_BACKGROUND, adjustBrightness(inputBgColor, 1.2f));
242242

243243
htmlStyled = htmlStyled.replace("${headerEnd}", "");
244244
htmlStyled = htmlStyled.replace("${nonce}", nonce);
@@ -290,6 +290,36 @@ public String getColorAsHex(String colorKey, String defaultColor) {
290290
});
291291
}
292292

293+
/**
294+
* Adjusts the brightness of a hex color by a given factor.
295+
* @param hexColor The hex color string (e.g., "#0e639c")
296+
* @param factor Brightness multiplier (> 1.0 for lighter, < 1.0 for darker)
297+
* @return Adjusted hex color string
298+
*/
299+
private String adjustBrightness(String hexColor, float factor) {
300+
if (hexColor == null || hexColor.isEmpty() || !hexColor.startsWith("#")) {
301+
return hexColor;
302+
}
303+
304+
try {
305+
// Parse hex color
306+
String hex = hexColor.substring(1);
307+
int r = Integer.parseInt(hex.substring(0, 2), 16);
308+
int g = Integer.parseInt(hex.substring(2, 4), 16);
309+
int b = Integer.parseInt(hex.substring(4, 6), 16);
310+
311+
// Adjust brightness
312+
r = Math.min(255, Math.max(0, (int)(r * factor)));
313+
g = Math.min(255, Math.max(0, (int)(g * factor)));
314+
b = Math.min(255, Math.max(0, (int)(b * factor)));
315+
316+
return String.format("#%02x%02x%02x", r, g, b);
317+
} catch (NumberFormatException | IndexOutOfBoundsException e) {
318+
SnykLogger.logError(new Exception("Failed to adjust brightness for color: " + hexColor, e));
319+
return hexColor;
320+
}
321+
}
322+
293323
public Boolean isDarkTheme() {
294324
var darkColor = getColorAsHex(THEME_DARK_BACKGROUND, "");
295325
return Boolean.valueOf(darkColor);

plugin/src/main/java/io/snyk/eclipse/plugin/preferences/HTMLSettingsPreferencePage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected Control createContents(Composite parent) {
5656
Composite container = new Composite(parent, SWT.NONE);
5757
container.setLayout(new FillLayout());
5858

59-
browser = new Browser(container, SWT.NONE);
59+
browser = new Browser(container, SWT.WEBKIT);
6060
initializeBrowserFunctions();
6161
loadContent();
6262

tests/src/test/java/io/snyk/eclipse/plugin/html/BaseHtmlProviderTest.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,6 @@ void replaceCssVariables_replacesFocusColor() {
8383
assertFalse(result.contains("var(--focus-color)"));
8484
}
8585

86-
@Test
87-
void replaceCssVariables_replacesVscodeVariables() {
88-
String html = "<div style=\"color: var(--vscode-foreground, #000)\">Test</div>";
89-
90-
String result = htmlProvider.replaceCssVariables(html);
91-
92-
assertFalse(result.contains("var(--vscode-foreground,"));
93-
}
94-
95-
@Test
96-
void replaceCssVariables_replacesVscodeInputBackground() {
97-
String html = "<input style=\"background: var(--vscode-input-background, #fff)\">";
98-
99-
String result = htmlProvider.replaceCssVariables(html);
100-
101-
assertFalse(result.contains("var(--vscode-input-background,"));
102-
}
103-
104-
@Test
105-
void replaceCssVariables_replacesVscodeFocusBorder() {
106-
String html = "<input style=\"border-color: var(--vscode-focusBorder, blue)\">";
107-
108-
String result = htmlProvider.replaceCssVariables(html);
109-
110-
assertFalse(result.contains("var(--vscode-focusBorder,"));
111-
}
112-
11386
@Test
11487
void replaceCssVariables_replacesNonce() {
11588
String html = "<style nonce=\"ideNonce\">body{}</style>";

0 commit comments

Comments
 (0)