@@ -10,13 +10,15 @@ import { addClasses } from '../utils';
10
10
import { BaseEvalElement } from './base' ;
11
11
12
12
// Premise used to connect to the first available pyodide interpreter
13
+
13
14
let pyodideReadyPromise ;
14
15
let environments ;
15
16
let currentMode ;
16
17
17
18
pyodideLoaded . subscribe ( value => {
18
19
pyodideReadyPromise = value ;
19
20
} ) ;
21
+
20
22
loadedEnvironments . subscribe ( value => {
21
23
environments = value ;
22
24
} ) ;
@@ -30,8 +32,6 @@ mode.subscribe(value => {
30
32
currentMode = value ;
31
33
} ) ;
32
34
33
- const languageConf = new Compartment ( ) ;
34
-
35
35
function createCmdHandler ( el ) {
36
36
// Creates a codemirror cmd handler that calls the el.evaluate when an event
37
37
// triggers that specific cmd
@@ -41,6 +41,15 @@ function createCmdHandler(el) {
41
41
return toggleCheckbox ;
42
42
}
43
43
44
+ let initialTheme ;
45
+ function getEditorTheme ( el : BaseEvalElement ) : string {
46
+ if ( initialTheme ) {
47
+ return initialTheme ;
48
+ }
49
+
50
+ return initialTheme = el . getAttribute ( 'theme' ) ;
51
+ }
52
+
44
53
export class PyRepl extends BaseEvalElement {
45
54
editor : EditorView ;
46
55
editorNode : HTMLElement ;
@@ -58,6 +67,7 @@ export class PyRepl extends BaseEvalElement {
58
67
this . checkId ( ) ;
59
68
this . code = this . innerHTML ;
60
69
this . innerHTML = '' ;
70
+ const languageConf = new Compartment ( ) ;
61
71
62
72
const extensions = [
63
73
basicSetup ,
@@ -68,29 +78,16 @@ export class PyRepl extends BaseEvalElement {
68
78
{ key : 'Shift-Enter' , run : createCmdHandler ( this ) } ,
69
79
] ) ,
70
80
] ;
71
- const customTheme = EditorView . theme ( {
72
- '&.cm-focused .cm-editor' : { outline : '0px' } ,
73
- '.cm-scroller' : { lineHeight : 2.5 } ,
74
- '.cm-activeLine' : { backgroundColor : '#fff' } ,
75
- '.cm-content' : { padding : 0 , backgroundColor : '#f5f5f5' } ,
76
- '&.cm-focused .cm-content' : { border : '1px solid #1876d2' } ,
77
- } ) ;
78
81
79
- if ( ! this . hasAttribute ( 'theme' ) ) {
80
- this . theme = this . getAttribute ( 'theme' ) ;
81
- if ( this . theme == 'dark' ) {
82
- extensions . push ( oneDarkTheme ) ;
83
- }
84
- extensions . push ( customTheme ) ;
82
+ if ( getEditorTheme ( this ) === 'dark' ) {
83
+ extensions . push ( oneDarkTheme ) ;
85
84
}
86
85
87
- const startState = EditorState . create ( {
88
- doc : this . code . trim ( ) ,
89
- extensions : extensions ,
90
- } ) ;
91
-
92
86
this . editor = new EditorView ( {
93
- state : startState ,
87
+ state : EditorState . create ( {
88
+ doc : this . code . trim ( ) ,
89
+ extensions,
90
+ } ) ,
94
91
parent : this . editorNode ,
95
92
} ) ;
96
93
@@ -176,15 +173,19 @@ export class PyRepl extends BaseEvalElement {
176
173
if ( this . hasAttribute ( 'auto-generate' ) ) {
177
174
const nextExecId = parseInt ( this . getAttribute ( 'exec-id' ) ) + 1 ;
178
175
const newPyRepl = document . createElement ( 'py-repl' ) ;
176
+
179
177
newPyRepl . setAttribute ( 'root' , this . getAttribute ( 'root' ) ) ;
180
178
newPyRepl . id = this . getAttribute ( 'root' ) + '-' + nextExecId . toString ( ) ;
181
179
newPyRepl . setAttribute ( 'auto-generate' , null ) ;
180
+
182
181
if ( this . hasAttribute ( 'output' ) ) {
183
182
newPyRepl . setAttribute ( 'output' , this . getAttribute ( 'output' ) ) ;
184
183
}
184
+
185
185
if ( this . hasAttribute ( 'std-out' ) ) {
186
186
newPyRepl . setAttribute ( 'std-out' , this . getAttribute ( 'std-out' ) ) ;
187
187
}
188
+
188
189
if ( this . hasAttribute ( 'std-err' ) ) {
189
190
newPyRepl . setAttribute ( 'std-err' , this . getAttribute ( 'std-err' ) ) ;
190
191
}
0 commit comments