@@ -3,6 +3,22 @@ import {basename, extname, isObject, isDarkTheme} from '../utils.js';
33const languagesByFilename = { } ;
44const languagesByExt = { } ;
55
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+
622function getEditorconfig ( input ) {
723 try {
824 return JSON . parse ( input . dataset . editorconfig ) ;
@@ -27,7 +43,7 @@ function getLanguage(filename) {
2743}
2844
2945function updateEditor ( monaco , editor , filename , lineWrapExts ) {
30- editor . updateOptions ( { ... getFileBasedOptions ( filename , lineWrapExts ) } ) ;
46+ editor . updateOptions ( getFileBasedOptions ( filename , lineWrapExts ) ) ;
3147 const model = editor . getModel ( ) ;
3248 const language = model . getModeId ( ) ;
3349 const newLanguage = getLanguage ( filename ) ;
@@ -51,9 +67,40 @@ export async function createMonaco(textarea, filename, editorOpts) {
5167 container . className = 'monaco-editor-container' ;
5268 textarea . parentNode . appendChild ( container ) ;
5369
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+
54101 const editor = monaco . editor . create ( container , {
55102 value : textarea . value ,
56- theme : isDarkTheme ( ) ? 'vs-dark' : 'vs ',
103+ theme : 'gitea ',
57104 language,
58105 ...other ,
59106 } ) ;
@@ -100,6 +147,7 @@ export async function createCodeEditor(textarea, filenameInput, previewFileModes
100147 }
101148
102149 const { monaco, editor} = await createMonaco ( textarea , filename , {
150+ ...baseOptions ,
103151 ...getFileBasedOptions ( filenameInput . value , lineWrapExts ) ,
104152 ...getEditorConfigOptions ( editorConfig ) ,
105153 } ) ;
0 commit comments