@@ -79,7 +79,9 @@ export class DrawioWidget extends DocumentWidget<Widget> {
79
79
onAfterShow ( msg : Message ) : void {
80
80
Private . ensureMx ( ) . then ( ( ) => {
81
81
this . _loadEditor ( this . node ) ;
82
- this . _onContentChanged ( ) ;
82
+ const contextModel = this . context . model ;
83
+ const xml = this . mx . mxUtils . parseXml ( contextModel . toString ( ) ) ;
84
+ this . _editor . editor . setGraphXml ( xml . documentElement ) ;
83
85
} ) ;
84
86
}
85
87
@@ -90,8 +92,8 @@ export class DrawioWidget extends DocumentWidget<Widget> {
90
92
private _onContextReady ( ) : void {
91
93
const contextModel = this . context . model ;
92
94
93
- // Set the editor model value.
94
- this . _onContentChanged ( ) ;
95
+ const xml = this . mx . mxUtils . parseXml ( contextModel . toString ( ) ) ;
96
+ this . _editor . editor . setGraphXml ( xml . documentElement ) ;
95
97
96
98
contextModel . contentChanged . connect ( this . _onContentChanged , this ) ;
97
99
contextModel . stateChanged . connect ( this . _onModelStateChangedNew , this ) ;
@@ -129,13 +131,17 @@ export class DrawioWidget extends DocumentWidget<Widget> {
129
131
// Workaround for TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature
130
132
const _Editor : any = mx . Editor ;
131
133
this . _editor = new mx . EditorUi ( new _Editor ( false , themes ) , node ) ;
132
-
134
+
133
135
this . _editor . editor . graph . model . addListener (
134
- mx . mxEvent . NOTIFY ,
136
+ mx . mxEvent . CHANGE ,
135
137
( sender : any , evt : any ) => {
138
+ //console.log(mx.mxEvent.CHANGE, sender, evt);
139
+ const changes : any [ ] = evt . properties . changes ;
140
+ for ( let i = 0 ; i < changes . length ; i ++ ) {
141
+ if ( changes [ i ] . root ) return ;
142
+ }
136
143
this . _saveToContext ( ) ;
137
- }
138
- ) ;
144
+ } ) ;
139
145
140
146
return this . _editor ;
141
147
}
@@ -157,17 +163,16 @@ export class DrawioWidget extends DocumentWidget<Widget> {
157
163
const newValue = this . context . model . toString ( ) ;
158
164
159
165
if ( oldValue !== newValue && ! this . _editor . editor . graph . isEditing ( ) ) {
160
- if ( newValue . length ) {
161
- const xml = mx . mxUtils . parseXml ( newValue ) ;
162
- this . _editor . editor . setGraphXml ( xml . documentElement ) ;
163
- }
166
+ const xml = mx . mxUtils . parseXml ( newValue ) ;
167
+ this . _editor . editor . setGraphXml ( xml . documentElement ) ;
164
168
}
165
169
}
166
170
167
171
private _saveToContext ( ) : void {
168
172
if ( this . _editor . editor . graph . isEditing ( ) ) {
169
173
this . _editor . editor . graph . stopEditing ( ) ;
170
174
}
175
+
171
176
const xml = this . mx . mxUtils . getXml ( this . _editor . editor . getGraphXml ( ) ) ;
172
177
this . context . model . fromString ( xml ) ;
173
178
}
0 commit comments