@@ -36,7 +36,7 @@ const PatternUtil = require( "../utils/PatternUtil" );
36
36
37
37
let wrapper , container , efflux , editorModel , keyboardController , stepHighlight ;
38
38
let interactionData = { } ,
39
- selectionModel , patternCopy , stepSelect ;
39
+ selectionModel , patternCopy , stepSelect , pContainers , pContainerSteps ;
40
40
41
41
const PatternTrackListController = module . exports =
42
42
{
@@ -110,12 +110,21 @@ const PatternTrackListController = module.exports =
110
110
const coordinates = { x : container . scrollLeft , y : container . scrollTop } ;
111
111
112
112
const pattern = efflux . activeSong . patterns [ activePattern ] ;
113
+
114
+ // render the currently active pattern on screen
115
+
113
116
efflux . TemplateService . render ( "patternTrackList" , wrapper , {
114
117
115
- steps : pattern . steps ,
116
- pattern : pattern
118
+ steps : pattern . steps ,
119
+ pattern : pattern ,
120
+ activeChannel : editorModel . activeInstrument ,
121
+ activeStep : editorModel . activeStep
117
122
118
- } ) . then ( highlightActiveStep ) ;
123
+ } ) . then ( ( ) => {
124
+ // clear cached containers after render
125
+ pContainers = null ;
126
+ pContainerSteps = [ ] ;
127
+ } ) ;
119
128
120
129
Form . setSelectedOption ( stepSelect , pattern . steps ) ;
121
130
container . scrollLeft = coordinates . x ;
@@ -188,8 +197,8 @@ function handleBroadcast( type, payload )
188
197
189
198
function highlightActiveStep ( )
190
199
{
191
- const pContainers = wrapper . querySelectorAll ( ".pattern" ) ,
192
- activeStyle = "active" , selectedStyle = "selected" ,
200
+ grabPatternContainersFromTemplate ( ) ;
201
+ const activeStyle = "active" , selectedStyle = "selected" ,
193
202
activeStep = editorModel . activeStep ;
194
203
195
204
let selection , pContainer , items , item ;
@@ -198,7 +207,8 @@ function highlightActiveStep()
198
207
{
199
208
pContainer = pContainers [ i ] ;
200
209
selection = selectionModel . selectedChannels [ i ] ;
201
- items = pContainer . querySelectorAll ( "li" ) ;
210
+ items = grabPatternContainerStepFromTemplate ( i ) ;
211
+ pContainer . querySelectorAll ( "li" ) ;
202
212
203
213
let j = items . length ;
204
214
while ( j -- )
@@ -243,7 +253,7 @@ function handleInteraction( aEvent )
243
253
244
254
if ( aEvent . target . nodeName === "LI" )
245
255
{
246
- const pContainers = wrapper . querySelectorAll ( ".pattern" ) ;
256
+ grabPatternContainersFromTemplate ( ) ;
247
257
let selectionChannelStart = editorModel . activeInstrument , selectionStepStart = editorModel . activeStep ;
248
258
let found = false , pContainer , items ;
249
259
@@ -257,7 +267,7 @@ function handleInteraction( aEvent )
257
267
if ( found ) break ;
258
268
259
269
pContainer = pContainers [ i ] ;
260
- items = pContainer . querySelectorAll ( "li" ) ;
270
+ items = grabPatternContainerStepFromTemplate ( i ) ;
261
271
262
272
let j = items . length ;
263
273
while ( j -- )
@@ -461,3 +471,17 @@ function addEventAtPosition( event, optData )
461
471
PatternTrackListController . update ( ) ;
462
472
Pubsub . publish ( Messages . SAVE_STATE ) ;
463
473
}
474
+
475
+ /**
476
+ * function to retrieve and cache the currently available DOM containers
477
+ * inside the pattern template
478
+ *
479
+ * @private
480
+ */
481
+ function grabPatternContainersFromTemplate ( ) {
482
+ pContainers = pContainers || wrapper . querySelectorAll ( ".pattern" ) ;
483
+ }
484
+
485
+ function grabPatternContainerStepFromTemplate ( i ) {
486
+ return ( pContainerSteps [ i ] = pContainerSteps [ i ] || pContainers [ i ] . querySelectorAll ( "li" ) ) ;
487
+ }
0 commit comments