File tree Expand file tree Collapse file tree 3 files changed +42
-20
lines changed
indigo_app/static/javascript/indigo/views Expand file tree Collapse file tree 3 files changed +42
-20
lines changed Original file line number Diff line number Diff line change 159
159
* Discard the content of all editors.
160
160
*/
161
161
discardChanges : function ( ) {
162
- this . tableEditor . discardChanges ( null , true ) ;
162
+ this . tableEditor . discardChanges ( true ) ;
163
163
this . aknTextEditor . discardChanges ( ) ;
164
164
if ( this . editing ) {
165
165
this . editActivityCancelled ( ) ;
Original file line number Diff line number Diff line change @@ -330,9 +330,7 @@ class XMLEditor {
330
330
331
331
setXmlElement ( element ) {
332
332
this . xmlElement = element ;
333
- if ( this . visible ) {
334
- this . render ( ) ;
335
- }
333
+ this . render ( ) ;
336
334
}
337
335
338
336
show ( ) {
@@ -347,17 +345,19 @@ class XMLEditor {
347
345
348
346
render ( ) {
349
347
// pretty-print the xml
350
- const xml = this . xmlElement ? prettyPrintXml ( Indigo . toXml ( this . xmlElement ) ) : '' ;
351
- if ( this . editor . getValue ( ) !== xml ) {
352
- const posn = this . editor . getPosition ( ) ;
348
+ if ( this . visible ) {
349
+ const xml = this . xmlElement ? prettyPrintXml ( Indigo . toXml ( this . xmlElement ) ) : '' ;
350
+ if ( this . editor . getValue ( ) !== xml ) {
351
+ const posn = this . editor . getPosition ( ) ;
353
352
354
- // ignore the onDidChangeModelContent event triggered by setValue
355
- this . updating = true ;
356
- this . editor . setValue ( xml ) ;
357
- this . updating = false ;
353
+ // ignore the onDidChangeModelContent event triggered by setValue
354
+ this . updating = true ;
355
+ this . editor . setValue ( xml ) ;
356
+ this . updating = false ;
358
357
359
- this . editor . setPosition ( posn ) ;
360
- this . editor . layout ( ) ;
358
+ this . editor . setPosition ( posn ) ;
359
+ this . editor . layout ( ) ;
360
+ }
361
361
}
362
362
}
363
363
@@ -397,19 +397,18 @@ class XMLEditor {
397
397
switch ( model . getMutationImpact ( mutation , this . xmlElement ) ) {
398
398
case 'replaced' :
399
399
this . xmlElement = mutation . addedNodes [ 0 ] ;
400
+ this . render ( ) ;
400
401
break ;
401
402
case 'changed' :
403
+ this . render ( ) ;
402
404
break ;
403
405
case 'removed' :
404
406
// the change removed xmlElement from the tree
405
407
console . log ( 'Mutation removes SourceEditor.xmlElement from the tree' ) ;
406
408
this . xmlElement = null ;
409
+ this . render ( ) ;
407
410
break ;
408
411
}
409
-
410
- if ( this . visible ) {
411
- this . render ( ) ;
412
- }
413
412
}
414
413
415
414
onNavTabChanged ( e ) {
Original file line number Diff line number Diff line change 30
30
} ,
31
31
32
32
initialize : function ( options ) {
33
- var self = this ;
34
-
35
33
this . parent = options . parent ;
36
34
this . documentContent = options . documentContent ;
35
+ this . documentContent . on ( 'mutation' , this . onDomMutated . bind ( this ) ) ;
37
36
this . tableWrapper = this . $ ( '.table-editor-wrapper' ) . removeClass ( 'd-none' ) . remove ( ) [ 0 ] ;
38
37
this . editing = false ;
39
38
77
76
return true ;
78
77
} ,
79
78
79
+ /**
80
+ * The XML document has changed, re-render if it impacts our table element.
81
+ *
82
+ * @param model documentContent model
83
+ * @param mutation a MutationRecord object
84
+ */
85
+ onDomMutated ( model , mutation ) {
86
+ if ( ! this . editing ) return ;
87
+
88
+ switch ( model . getMutationImpact ( mutation , this . table ) ) {
89
+ case 'replaced' :
90
+ this . discardChanges ( true ) ;
91
+ break ;
92
+ case 'changed' :
93
+ this . discardChanges ( true ) ;
94
+ break ;
95
+ case 'removed' :
96
+ // the change removed xmlElement from the tree
97
+ console . log ( 'Mutation removes TableEditor.table from the tree' ) ;
98
+ this . discardChanges ( true ) ;
99
+ break ;
100
+ }
101
+ } ,
102
+
80
103
saveChanges : function ( e ) {
81
104
if ( ! this . editing || ! this . table ) return ;
82
105
111
134
this . trigger ( 'save' ) ;
112
135
} ,
113
136
114
- discardChanges : function ( e , force ) {
137
+ discardChanges : function ( force ) {
115
138
if ( ! this . editing || ! this . table ) return ;
116
139
if ( ! force && ! confirm ( $t ( "You'll lose your changes, are you sure?" ) ) ) return ;
117
140
You can’t perform that action at this time.
0 commit comments