Skip to content

Commit dbd3c33

Browse files
[8.19] [Vega] Change Vega editor inactiveSelectionBackground color in dark mode to match Monaco Editor dark theme (#229589) (#229803)
# Backport This will backport the following commits from `main` to `8.19`: - [[Vega] Change Vega editor inactiveSelectionBackground color in dark mode to match Monaco Editor dark theme (#229589)](#229589) <!--- Backport version: 10.0.1 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Krzysztof Kowalczyk","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-07-29T12:39:09Z","message":"[Vega] Change Vega editor inactiveSelectionBackground color in dark mode to match Monaco Editor dark theme (#229589)\n\n## Summary\n\nThis PR fixes wrong color being used for when you have text selected in\nVega editor and the editor isn't focused. After the change, the color\nmatches the default value used in Monaco Editor dark theme.\n\n| Before | After |\n|--------|-------|\n| <img width=\"373\" height=\"995\" alt=\"Before\"\nsrc=\"https://github.com/user-attachments/assets/183684db-a1f4-43b4-bc1d-f3c5e9c1193d\"\n/> | <img width=\"371\" height=\"946\" alt=\"After\"\nsrc=\"https://github.com/user-attachments/assets/ee965d26-8016-45af-b6f1-1ed86953467c\"\n/> |\n\nCloses: #228296","sha":"95a18def87020db328b1bf89369f634395e13879","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Vega","Team:Visualizations","release_note:skip","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[Vega] Change Vega editor inactiveSelectionBackground color in dark mode to match Monaco Editor dark theme","number":229589,"url":"https://github.com/elastic/kibana/pull/229589","mergeCommit":{"message":"[Vega] Change Vega editor inactiveSelectionBackground color in dark mode to match Monaco Editor dark theme (#229589)\n\n## Summary\n\nThis PR fixes wrong color being used for when you have text selected in\nVega editor and the editor isn't focused. After the change, the color\nmatches the default value used in Monaco Editor dark theme.\n\n| Before | After |\n|--------|-------|\n| <img width=\"373\" height=\"995\" alt=\"Before\"\nsrc=\"https://github.com/user-attachments/assets/183684db-a1f4-43b4-bc1d-f3c5e9c1193d\"\n/> | <img width=\"371\" height=\"946\" alt=\"After\"\nsrc=\"https://github.com/user-attachments/assets/ee965d26-8016-45af-b6f1-1ed86953467c\"\n/> |\n\nCloses: #228296","sha":"95a18def87020db328b1bf89369f634395e13879"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/229589","number":229589,"mergeCommit":{"message":"[Vega] Change Vega editor inactiveSelectionBackground color in dark mode to match Monaco Editor dark theme (#229589)\n\n## Summary\n\nThis PR fixes wrong color being used for when you have text selected in\nVega editor and the editor isn't focused. After the change, the color\nmatches the default value used in Monaco Editor dark theme.\n\n| Before | After |\n|--------|-------|\n| <img width=\"373\" height=\"995\" alt=\"Before\"\nsrc=\"https://github.com/user-attachments/assets/183684db-a1f4-43b4-bc1d-f3c5e9c1193d\"\n/> | <img width=\"371\" height=\"946\" alt=\"After\"\nsrc=\"https://github.com/user-attachments/assets/ee965d26-8016-45af-b6f1-1ed86953467c\"\n/> |\n\nCloses: #228296","sha":"95a18def87020db328b1bf89369f634395e13879"}}]}] BACKPORT-->
1 parent b9ca831 commit dbd3c33

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/platform/plugins/private/vis_types/vega/public/components/vega_vis_editor.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import { XJsonLang } from '@kbn/monaco';
1111
import useMount from 'react-use/lib/useMount';
1212
import hjson from 'hjson';
1313

14-
import React, { useCallback, useState } from 'react';
14+
import React, { useCallback, useMemo, useState } from 'react';
1515
import compactStringify from 'json-stringify-pretty-compact';
1616
import { i18n } from '@kbn/i18n';
1717

1818
import { VisEditorOptionsProps } from '@kbn/visualizations-plugin/public';
1919
import { CodeEditor, HJsonLang } from '@kbn/code-editor';
20+
import { css } from '@emotion/react';
21+
import { type UseEuiTheme, useEuiTheme } from '@elastic/eui';
22+
import { type CSSInterpolation } from '@emotion/css';
2023
import { getNotifications } from '../services';
2124
import { VisParams } from '../vega_fn';
2225
import { VegaHelpMenu } from './vega_help_menu';
@@ -48,7 +51,38 @@ function format(
4851
}
4952
}
5053

54+
type EmotionStyles = Record<string, CSSInterpolation | ((theme: UseEuiTheme) => CSSInterpolation)>;
55+
56+
const useMemoCss = <T extends EmotionStyles>(styleMap: T): { [K in keyof T]: CSSInterpolation } => {
57+
const euiThemeContext = useEuiTheme();
58+
59+
const outputStyles = useMemo(() => {
60+
return Object.entries(styleMap).reduce<{ [K in keyof T]: CSSInterpolation }>(
61+
(acc, [key, value]) => {
62+
acc[key as keyof T] = typeof value === 'function' ? value(euiThemeContext) : value;
63+
return acc;
64+
},
65+
{} as { [K in keyof T]: CSSInterpolation }
66+
);
67+
}, [euiThemeContext, styleMap]);
68+
69+
return outputStyles;
70+
};
71+
72+
const monacoOverride = {
73+
override: ({ colorMode }: UseEuiTheme) =>
74+
css({
75+
// See discussion: https://github.com/elastic/kibana/issues/228296#issuecomment-3126033291
76+
...(colorMode === 'DARK' && {
77+
'.monaco-editor': {
78+
'--vscode-editor-inactiveSelectionBackground': '#3a3d41',
79+
},
80+
}),
81+
}),
82+
};
83+
5184
function VegaVisEditor({ stateParams, setValue }: VisEditorOptionsProps<VisParams>) {
85+
const monacoStyles = useMemoCss(monacoOverride);
5286
const [languageId, setLanguageId] = useState<string>();
5387

5488
useMount(() => {
@@ -103,6 +137,7 @@ function VegaVisEditor({ stateParams, setValue }: VisEditorOptionsProps<VisParam
103137
<VegaActionsMenu formatHJson={formatHJson} formatJson={formatJson} />
104138
</div>
105139
<CodeEditor
140+
classNameCss={monacoStyles.override}
106141
width="100%"
107142
height="100%"
108143
languageId={languageId}

0 commit comments

Comments
 (0)