@@ -25,52 +25,59 @@ class MonacoDiffEditor extends React.Component<MonacoDiffEditorProps> {
2525 }
2626
2727 componentDidUpdate ( prevProps ) {
28- const { language, theme, options, sync, readOnly } = this . props ;
28+ const { language, theme, options, sync } = this . props ;
2929 const { original, modified } = this . diffEditor . getModel ( ) ;
3030
31+ if ( prevProps . language !== language ) {
32+ editor . setModelLanguage ( original , language ) ;
33+ editor . setModelLanguage ( modified , language ) ;
34+ }
35+ if ( prevProps . theme !== theme ) {
36+ editor . setTheme ( theme ) ;
37+ }
38+ if ( prevProps . options !== options ) {
39+ this . diffEditor . updateOptions ( {
40+ ...options ,
41+ } ) ;
42+ }
43+
3144 if ( this . props . original !== original . getValue ( ) && sync ) {
3245 original . setValue ( this . props . original ) ;
3346 }
47+
3448 if (
3549 this . props . value != null &&
3650 this . props . value !== modified . getValue ( ) &&
3751 sync
3852 ) {
3953 this . __prevent_onChange = true ;
40- this . diffEditor . getModifiedEditor ( ) . updateOptions ( {
41- readOnly : false ,
42- } ) ;
43- this . diffEditor . getModifiedEditor ( ) . pushUndoStop ( ) ;
44- this . diffEditor . getModifiedEditor ( ) . executeEdits ( 'sync-value' , [
54+ const modifiedEditor = this . diffEditor . getModifiedEditor ( ) ;
55+
56+ const readOnly = modifiedEditor . getRawOptions ( ) . readOnly ;
57+
58+ if ( readOnly ) {
59+ modifiedEditor . updateOptions ( {
60+ readOnly : false ,
61+ } ) ;
62+ }
63+
64+ modifiedEditor . pushUndoStop ( ) ;
65+ modifiedEditor . executeEdits ( 'sync-value' , [
4566 {
4667 range : modified . getFullModelRange ( ) ,
4768 text : this . props . value ,
4869 forceMoveMarkers : true ,
4970 } ,
5071 ] ) ;
51- this . diffEditor . getModifiedEditor ( ) . pushUndoStop ( ) ;
52- this . diffEditor . getModifiedEditor ( ) . updateOptions ( {
53- readOnly,
54- } ) ;
72+ modifiedEditor . pushUndoStop ( ) ;
73+
74+ if ( readOnly ) {
75+ modifiedEditor . updateOptions ( {
76+ readOnly : readOnly ,
77+ } ) ;
78+ }
5579 this . __prevent_onChange = false ;
5680 }
57- if ( prevProps . language !== language ) {
58- editor . setModelLanguage ( original , language ) ;
59- editor . setModelLanguage ( modified , language ) ;
60- }
61- if ( prevProps . theme !== theme ) {
62- editor . setTheme ( theme ) ;
63- }
64- if ( prevProps . options !== options ) {
65- this . diffEditor . updateOptions ( {
66- ...options ,
67- } ) ;
68- }
69- if ( prevProps . readOnly !== readOnly ) {
70- this . diffEditor . getModifiedEditor ( ) . updateOptions ( {
71- readOnly,
72- } ) ;
73- }
7481 }
7582
7683 componentWillUnmount ( ) {
@@ -79,14 +86,7 @@ class MonacoDiffEditor extends React.Component<MonacoDiffEditorProps> {
7986 }
8087
8188 initMonaco ( ) {
82- const {
83- original,
84- value,
85- language,
86- options,
87- theme = 'vs' ,
88- readOnly,
89- } = this . props ;
89+ const { original, value, language, options, theme = 'vs' } = this . props ;
9090 if ( ! this . monacoDom . current ) {
9191 console . error ( 'Can not get monacoDom element!' ) ;
9292 return ;
@@ -113,9 +113,6 @@ class MonacoDiffEditor extends React.Component<MonacoDiffEditorProps> {
113113 original : originalModel ,
114114 modified : modifiedModel ,
115115 } ) ;
116- this . diffEditor . getModifiedEditor ( ) . updateOptions ( {
117- readOnly : readOnly ,
118- } ) ;
119116
120117 this . initEditorEvent ( ) ;
121118 this . props . editorDidMount ?.( this . diffEditor ) ;
0 commit comments