11import React , { useEffect } from 'react'
22import { EditorView } from '@codemirror/view'
3- import { EditorState } from '@codemirror/state'
3+ import { EditorState , Transaction } from '@codemirror/state'
44import { basicSetup } from '@codemirror/basic-setup'
5- import { javaLanguage } from '@codemirror/lang-java'
65import { tags , HighlightStyle } from '@codemirror/highlight'
76
87export interface EditorProperties {
@@ -36,8 +35,37 @@ const theme = EditorView.theme({
3635 color : "#ddd" ,
3736 border : "none"
3837 } ,
38+
3939} , { dark : false } )
4040
41+ const darkTheme = EditorView . theme ( {
42+ ".cm-scroller" : {
43+ fontFamily : `'JetBrains Mono', Menlo, Monaco, source-code-pro, Consolas, monospace`
44+ } ,
45+ "&" : {
46+ color : "#f6f8fa" ,
47+ backgroundColor : "#24292e" ,
48+ padding : "10px 0"
49+ } ,
50+ ".cm-activeLineGutter, .cm-activeLine" : {
51+ backgroundColor : "#24292e"
52+ } ,
53+ ".cm-content" : {
54+ caretColor : "#24292e"
55+ } ,
56+ "&.cm-focused .cm-cursor" : {
57+ borderLeftColor : "#24292e"
58+ } ,
59+ "&.cm-focused .cm-selectionBackground, ::selection" : {
60+ backgroundColor : "#24292e"
61+ } ,
62+ ".cm-gutters" : {
63+ backgroundColor : "#24292e" ,
64+ color : "#24292e" ,
65+ border : "none"
66+ } ,
67+ } , { dark : true } )
68+
4169const githubHighlighting = HighlightStyle . define ( [
4270 { tag : tags . function , color : '#6f42c1' } ,
4371 { tag : tags . className , color : '#6f42c1' } ,
@@ -54,6 +82,21 @@ const githubHighlighting = HighlightStyle.define([
5482 { tag : tags . comment , color : '#6a737d' }
5583] )
5684
85+ const githubDarkHighlighting = HighlightStyle . define ( [
86+ { tag : tags . function , color : '#dcbdfb' } ,
87+ { tag : tags . className , color : '#dcbdfb' } ,
88+ { tag : tags . keyword , color : '#f47067' } ,
89+ { tag : tags . definitionKeyword , color : '#f47067' } ,
90+ { tag : tags . controlKeyword , color : '#f47067' } ,
91+ { tag : tags . operatorKeyword , color : '#f47067' } ,
92+ { tag : tags . function ( tags . variableName ) , color : "#f69d50" } ,
93+ { tag : tags . constant , color : '#6cb6ff' } ,
94+ { tag : tags . operator , color : '#f47067' } ,
95+ { tag : tags . number , color : '#6cb6ff' } ,
96+ { tag : tags . string , color : '#96d0ff' } ,
97+ { tag : tags . comment , color : '#768390' }
98+ ] )
99+
57100export default function Editor ( properties : EditorProperties ) {
58101 const element = React . createRef < HTMLDivElement > ( )
59102 const editor = React . useRef < { editor : EditorView | undefined } > ( { editor : undefined } )
@@ -64,7 +107,7 @@ export default function Editor(properties: EditorProperties) {
64107 const created = new EditorView ( {
65108 state : EditorState . create ( {
66109 doc : properties . code ,
67- extensions : [ theme , basicSetup , javaLanguage , githubHighlighting ]
110+ extensions : [ darkTheme , basicSetup , javaLanguage , githubDarkHighlighting ]
68111 } ) ,
69112 parent : element . current ! ,
70113 } )
0 commit comments