@@ -54,7 +54,10 @@ export default class Text extends EventDispatcher {
54
54
}
55
55
56
56
set tests ( val ) {
57
- val = val instanceof Array ? val : [ ] ;
57
+ if ( ! ( val instanceof Array ) ) {
58
+ val = [ ] ;
59
+ $ . removeClass ( this . testsEl , "tests-added" ) ;
60
+ }
58
61
this . _tests = this . testList . data = val ;
59
62
this . _testMatches = null ;
60
63
this . _reselectTest ( ) ;
@@ -96,6 +99,15 @@ export default class Text extends EventDispatcher {
96
99
}
97
100
return null ;
98
101
}
102
+
103
+ getEmptyTest ( ) {
104
+ return {
105
+ id : UID . id ,
106
+ name : "" ,
107
+ text : "Enter your test text here." ,
108
+ type : "any"
109
+ }
110
+ }
99
111
100
112
// private methods:
101
113
_initUI ( el ) {
@@ -142,6 +154,7 @@ export default class Text extends EventDispatcher {
142
154
_handleModeChange ( evt ) {
143
155
this . dispatchEvent ( "modechange" ) ;
144
156
if ( this . mode === "text" ) { this . editor . refresh ( ) ; }
157
+ else { $ . addClass ( this . el , "tests-viewed" ) ; }
145
158
}
146
159
147
160
_setResult ( val ) {
@@ -276,10 +289,11 @@ export default class Text extends EventDispatcher {
276
289
] ;
277
290
this . typeLabels = types . reduce ( ( o , t ) => { o [ t . id ] = t . label ; return o ; } , { } ) ;
278
291
292
+ this . testsEl = $ . query ( ".tests" , el ) ;
279
293
this . testItemEl = $ . query ( "#library > #tests_item" ) ;
280
- this . testListEl = $ . query ( ".tests . list" , el ) ;
294
+ this . testListEl = $ . query ( ".list" , this . testsEl ) ;
281
295
this . testList = new List ( this . testListEl , { template :( o ) => this . _testItemTemplate ( o ) } ) ;
282
- this . testList . scrollEl = $ . query ( ".tests" , el ) ;
296
+ this . testList . scrollEl = this . testsEl ;
283
297
284
298
this . testList . on ( "change" , ( evt ) => this . _handleTestChange ( evt ) ) ;
285
299
@@ -364,16 +378,12 @@ export default class Text extends EventDispatcher {
364
378
}
365
379
366
380
_addTest ( ) {
367
- const o = {
368
- id : UID . id ,
369
- name : "" ,
370
- text : "Enter your test text here." ,
371
- type : "any"
372
- }
381
+ const o = this . getEmptyTest ( ) ;
373
382
this . _tests . push ( o ) ;
374
383
this . testList . addItem ( o , true ) ;
375
384
this . _handleTestChange ( ) ;
376
385
this . testEditor . execCommand ( "selectAll" ) ;
386
+ $ . addClass ( this . testsEl , "tests-added" ) ;
377
387
this . _change ( ) ;
378
388
}
379
389
0 commit comments