Skip to content

Commit 543096a

Browse files
authored
fix: light background in dark mode (#55)
1 parent b5487e9 commit 543096a

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

resources/monaco/src/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ body {
77
overflow: hidden;
88
}
99

10+
body, .monaco-editor, .monaco-editor-background, .monaco-editor .inputarea.ime-input {
11+
background-color: var(--vscode-editor-background) !important;
12+
}
13+
1014
#container {
1115
height: 100%;
1216
}

resources/monaco/src/utils.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function render(
99
_diffEditor,
1010
{ rightPath, notSupportedFile, leftContent, rightContent, theme, tabSize }
1111
) {
12+
setTheme(theme);
1213
diffEditor = _diffEditor;
1314
window.diffEditor = _diffEditor;
1415
diffEditor.setModel({
@@ -28,7 +29,6 @@ export function render(
2829
diffEditor.modifiedEditor.onDidChangeModelContent(onDidUpdateDiff);
2930
bindSaveShortcut();
3031
extractEditorStyles(diffEditor);
31-
setTheme(theme);
3232
setTabSize(tabSize);
3333
}
3434

@@ -256,8 +256,12 @@ function setTheme(theme) {
256256
if (!theme) {
257257
return;
258258
}
259-
monaco.editor.defineTheme('vscodeTheme', theme);
260-
monaco.editor.setTheme('vscodeTheme');
259+
try {
260+
monaco.editor.defineTheme('vscodeTheme', theme);
261+
monaco.editor.setTheme('vscodeTheme');
262+
} catch (e) {
263+
console.log(e);
264+
}
261265
}
262266

263267
function retrieveCssVariables() {

src/theme/adapter.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
const COMMENTED_LINE_REGEX = /^.*\/\/.*$\n/gm;
2+
const TRALING_COMMA_REGEX = /\,(?=\s*?[\}\]])/g;
3+
4+
15
export function convertToMonacoTheme(text: string) {
26
try {
37
const vscodeTheme = JSON.parse(
48
text
5-
.replace(/\/\//gm, '')
9+
.replace(COMMENTED_LINE_REGEX, '')
10+
.replace(TRALING_COMMA_REGEX, '')
611
);
712

813
const rules = vscodeTheme.tokenColors.map((c: {scope: any, settings: any}) => ({

0 commit comments

Comments
 (0)