|
| 1 | +import tinycolor from 'tinycolor2'; |
1 | 2 | import {basename, extname, isObject, isDarkTheme} from '../utils.js';
|
2 | 3 | import {onInputDebounce} from '../utils/dom.js';
|
3 | 4 |
|
@@ -69,33 +70,34 @@ export async function createMonaco(textarea, filename, editorOpts) {
|
69 | 70 | textarea.parentNode.append(container);
|
70 | 71 |
|
71 | 72 | // https://github.com/microsoft/monaco-editor/issues/2427
|
| 73 | + // also, monaco can only parse 6-digit hex colors, so we convert the colors to that format |
72 | 74 | const styles = window.getComputedStyle(document.documentElement);
|
73 |
| - const getProp = (name) => styles.getPropertyValue(name).trim(); |
| 75 | + const getColor = (name) => tinycolor(styles.getPropertyValue(name).trim()).toString('hex6'); |
74 | 76 |
|
75 | 77 | monaco.editor.defineTheme('gitea', {
|
76 | 78 | base: isDarkTheme() ? 'vs-dark' : 'vs',
|
77 | 79 | inherit: true,
|
78 | 80 | rules: [
|
79 | 81 | {
|
80 |
| - background: getProp('--color-code-bg'), |
| 82 | + background: getColor('--color-code-bg'), |
81 | 83 | }
|
82 | 84 | ],
|
83 | 85 | colors: {
|
84 |
| - 'editor.background': getProp('--color-code-bg'), |
85 |
| - 'editor.foreground': getProp('--color-text'), |
86 |
| - 'editor.inactiveSelectionBackground': getProp('--color-primary-light-4'), |
87 |
| - 'editor.lineHighlightBackground': getProp('--color-editor-line-highlight'), |
88 |
| - 'editor.selectionBackground': getProp('--color-primary-light-3'), |
89 |
| - 'editor.selectionForeground': getProp('--color-primary-light-3'), |
90 |
| - 'editorLineNumber.background': getProp('--color-code-bg'), |
91 |
| - 'editorLineNumber.foreground': getProp('--color-secondary-dark-6'), |
92 |
| - 'editorWidget.background': getProp('--color-body'), |
93 |
| - 'editorWidget.border': getProp('--color-secondary'), |
94 |
| - 'input.background': getProp('--color-input-background'), |
95 |
| - 'input.border': getProp('--color-input-border'), |
96 |
| - 'input.foreground': getProp('--color-input-text'), |
97 |
| - 'scrollbar.shadow': getProp('--color-shadow'), |
98 |
| - 'progressBar.background': getProp('--color-primary'), |
| 86 | + 'editor.background': getColor('--color-code-bg'), |
| 87 | + 'editor.foreground': getColor('--color-text'), |
| 88 | + 'editor.inactiveSelectionBackground': getColor('--color-primary-light-4'), |
| 89 | + 'editor.lineHighlightBackground': getColor('--color-editor-line-highlight'), |
| 90 | + 'editor.selectionBackground': getColor('--color-primary-light-3'), |
| 91 | + 'editor.selectionForeground': getColor('--color-primary-light-3'), |
| 92 | + 'editorLineNumber.background': getColor('--color-code-bg'), |
| 93 | + 'editorLineNumber.foreground': getColor('--color-secondary-dark-6'), |
| 94 | + 'editorWidget.background': getColor('--color-body'), |
| 95 | + 'editorWidget.border': getColor('--color-secondary'), |
| 96 | + 'input.background': getColor('--color-input-background'), |
| 97 | + 'input.border': getColor('--color-input-border'), |
| 98 | + 'input.foreground': getColor('--color-input-text'), |
| 99 | + 'scrollbar.shadow': getColor('--color-shadow'), |
| 100 | + 'progressBar.background': getColor('--color-primary'), |
99 | 101 | }
|
100 | 102 | });
|
101 | 103 |
|
|
0 commit comments