@@ -3,6 +3,22 @@ import {basename, extname, isObject, isDarkTheme} from '../utils.js';
3
3
const languagesByFilename = { } ;
4
4
const languagesByExt = { } ;
5
5
6
+ const baseOptions = {
7
+ fontFamily : 'var(--fonts-monospace)' ,
8
+ fontSize : 14 , // https://github.com/microsoft/monaco-editor/issues/2242
9
+ links : false ,
10
+ minimap : { enabled : false } ,
11
+ occurrencesHighlight : false ,
12
+ overviewRulerLanes : 0 ,
13
+ renderIndentGuides : false ,
14
+ renderLineHighlight : 'all' ,
15
+ renderLineHighlightOnlyWhenFocus : true ,
16
+ renderWhitespace : 'none' ,
17
+ rulers : false ,
18
+ scrollbar : { horizontalScrollbarSize : 6 , verticalScrollbarSize : 6 } ,
19
+ scrollBeyondLastLine : false ,
20
+ } ;
21
+
6
22
function getEditorconfig ( input ) {
7
23
try {
8
24
return JSON . parse ( input . dataset . editorconfig ) ;
@@ -27,7 +43,7 @@ function getLanguage(filename) {
27
43
}
28
44
29
45
function updateEditor ( monaco , editor , filename , lineWrapExts ) {
30
- editor . updateOptions ( { ... getFileBasedOptions ( filename , lineWrapExts ) } ) ;
46
+ editor . updateOptions ( getFileBasedOptions ( filename , lineWrapExts ) ) ;
31
47
const model = editor . getModel ( ) ;
32
48
const language = model . getModeId ( ) ;
33
49
const newLanguage = getLanguage ( filename ) ;
@@ -51,9 +67,40 @@ export async function createMonaco(textarea, filename, editorOpts) {
51
67
container . className = 'monaco-editor-container' ;
52
68
textarea . parentNode . appendChild ( container ) ;
53
69
70
+ // https://github.com/microsoft/monaco-editor/issues/2427
71
+ const styles = window . getComputedStyle ( document . documentElement ) ;
72
+ const getProp = ( name ) => styles . getPropertyValue ( name ) . trim ( ) ;
73
+
74
+ monaco . editor . defineTheme ( 'gitea' , {
75
+ base : isDarkTheme ( ) ? 'vs-dark' : 'vs' ,
76
+ inherit : true ,
77
+ rules : [
78
+ {
79
+ background : getProp ( '--color-code-bg' ) ,
80
+ }
81
+ ] ,
82
+ colors : {
83
+ 'editor.background' : getProp ( '--color-code-bg' ) ,
84
+ 'editor.foreground' : getProp ( '--color-text' ) ,
85
+ 'editor.inactiveSelectionBackground' : getProp ( '--color-primary-light-4' ) ,
86
+ 'editor.lineHighlightBackground' : getProp ( '--color-editor-line-highlight' ) ,
87
+ 'editor.selectionBackground' : getProp ( '--color-primary-light-3' ) ,
88
+ 'editor.selectionForeground' : getProp ( '--color-primary-light-3' ) ,
89
+ 'editorLineNumber.background' : getProp ( '--color-code-bg' ) ,
90
+ 'editorLineNumber.foreground' : getProp ( '--color-secondary-dark-6' ) ,
91
+ 'editorWidget.background' : getProp ( '--color-body' ) ,
92
+ 'editorWidget.border' : getProp ( '--color-secondary' ) ,
93
+ 'input.background' : getProp ( '--color-input-background' ) ,
94
+ 'input.border' : getProp ( '--color-input-border' ) ,
95
+ 'input.foreground' : getProp ( '--color-input-text' ) ,
96
+ 'scrollbar.shadow' : getProp ( '--color-shadow' ) ,
97
+ 'progressBar.background' : getProp ( '--color-primary' ) ,
98
+ }
99
+ } ) ;
100
+
54
101
const editor = monaco . editor . create ( container , {
55
102
value : textarea . value ,
56
- theme : isDarkTheme ( ) ? 'vs-dark' : 'vs ',
103
+ theme : 'gitea ',
57
104
language,
58
105
...other ,
59
106
} ) ;
@@ -100,6 +147,7 @@ export async function createCodeEditor(textarea, filenameInput, previewFileModes
100
147
}
101
148
102
149
const { monaco, editor} = await createMonaco ( textarea , filename , {
150
+ ...baseOptions ,
103
151
...getFileBasedOptions ( filenameInput . value , lineWrapExts ) ,
104
152
...getEditorConfigOptions ( editorConfig ) ,
105
153
} ) ;
0 commit comments