@@ -32,11 +32,12 @@ type HotKey = {
3232
3333const Editor : React . FC < {
3434 id : string ;
35- script : ScriptAndCode ;
35+ script : Script ;
36+ code : string ;
3637 hotKeys : HotKey [ ] ;
3738 callbackEditor : ( e : editor . IStandaloneCodeEditor ) => void ;
3839 onChange : ( code : string ) => void ;
39- } > = ( { id, script, hotKeys, callbackEditor, onChange } ) => {
40+ } > = ( { id, script, code , hotKeys, callbackEditor, onChange } ) => {
4041 const [ node , setNode ] = useState < { editor : editor . IStandaloneCodeEditor } > ( ) ;
4142 const ref = useCallback < ( node : { editor : editor . IStandaloneCodeEditor } ) => void > (
4243 ( inlineNode ) => {
@@ -77,7 +78,7 @@ const Editor: React.FC<{
7778 } ;
7879 } , [ node ?. editor ] ) ;
7980
80- return < CodeEditor key = { id } id = { id } ref = { ref } code = { script . code } diffCode = "" editable /> ;
81+ return < CodeEditor key = { id } id = { id } ref = { ref } code = { code } diffCode = "" editable /> ;
8182} ;
8283
8384const WarpEditor = React . memo ( Editor , ( prev , next ) => {
@@ -154,7 +155,8 @@ function ScriptEditor() {
154155 const [ visible , setVisible ] = useState < { [ key : string ] : boolean } > ( { } ) ;
155156 const [ editors , setEditors ] = useState <
156157 {
157- script : ScriptAndCode ;
158+ script : Script ;
159+ code : string ;
158160 active : boolean ;
159161 hotKeys : HotKey [ ] ;
160162 editor ?: editor . IStandaloneCodeEditor ;
@@ -218,7 +220,7 @@ function ScriptEditor() {
218220 setEditors ( ( prev ) => {
219221 for ( let i = 0 ; i < prev . length ; i += 1 ) {
220222 if ( prev [ i ] . script . uuid === newScript . uuid ) {
221- prev [ i ] . script . code = prepareScript . scriptCode ;
223+ prev [ i ] . code = e . getValue ( ) ;
222224 prev [ i ] . isChanged = false ;
223225 prev [ i ] . script . name = newScript . name ;
224226 break ;
@@ -310,7 +312,7 @@ function ScriptEditor() {
310312 } ) ;
311313 } )
312314 . catch ( ( err ) => {
313- LoggerCore . getLogger ( Logger . E ( err ) ) . debug ( "debug script error" ) ;
315+ LoggerCore . logger ( Logger . E ( err ) ) . debug ( "debug script error" ) ;
314316 Message . error ( {
315317 id : "debug_script" ,
316318 content : `构建失败: ${ err } ` ,
@@ -398,7 +400,8 @@ function ScriptEditor() {
398400 } ) ;
399401 }
400402 prev . push ( {
401- script : Object . assign ( scripts [ i ] , code ) ,
403+ script : scripts [ i ] ,
404+ code : code ?. code || "" ,
402405 active : true ,
403406 hotKeys,
404407 isChanged : false ,
@@ -725,7 +728,8 @@ function ScriptEditor() {
725728 return ;
726729 }
727730 editors . push ( {
728- script : Object . assign ( script , code ) ,
731+ script,
732+ code : code . code ,
729733 active : true ,
730734 hotKeys,
731735 isChanged : false ,
@@ -874,6 +878,7 @@ function ScriptEditor() {
874878 key = { `e_${ item . script . uuid } ` }
875879 id = { `e_${ item . script . uuid } ` }
876880 script = { item . script }
881+ code = { item . code }
877882 hotKeys = { item . hotKeys }
878883 callbackEditor = { ( e ) => {
879884 setEditors ( ( prev ) => {
@@ -886,7 +891,7 @@ function ScriptEditor() {
886891 } ) ;
887892 } }
888893 onChange = { ( code ) => {
889- const isChanged = ! ( item . script . code === code ) ;
894+ const isChanged = ! ( item . code === code ) ;
890895 if ( isChanged !== item . isChanged ) {
891896 setEditors ( ( prev ) => {
892897 prev . forEach ( ( v ) => {
0 commit comments