@@ -153,8 +153,6 @@ export class UndoBuffer {
153153   */ 
154154  addBuffer ( title : string ,  type : number ,  selector : SmoSelector ,  obj : any ,  subtype : number )  { 
155155    this . checkNull ( ) ; 
156-     let  i  =  0 ; 
157-     let  j  =  0 ; 
158156    if  ( typeof ( type )  !==  'number'  ||  type  <  UndoBuffer . bufferTypes . FIRST  ||  type  >  UndoBuffer . bufferTypes . LAST )  { 
159157      throw  'Undo failure: illegal buffer type '  +  type ; 
160158    } 
@@ -169,8 +167,8 @@ export class UndoBuffer {
169167      // RECTANGLE obj is {score, topLeft, bottomRight} 
170168      // where the last 2 are selectors 
171169      const  measures  =  [ ] ; 
172-       for  ( i  =  obj . topLeft . staff ;  i  <=  obj . bottomRight . staff ;  ++ i )  { 
173-         for  ( j  =  obj . topLeft . measure ;  j  <=  obj . bottomRight . measure ;  ++ j )  { 
170+       for  ( let   i  =  obj . topLeft . staff ;  i  <=  obj . bottomRight . staff ;  ++ i )  { 
171+         for  ( let   j  =  obj . topLeft . measure ;  j  <=  obj . bottomRight . measure ;  ++ j )  { 
174172          measures . push ( UndoBuffer . serializeMeasure ( obj . score . staves [ i ] . measures [ j ] ) ) ; 
175173        } 
176174      } 
@@ -295,17 +293,21 @@ export class UndoBuffer {
295293          return  [ buf . json . startSelector . measure ,  buf . json . endSelector . measure ] ; 
296294        } 
297295        if  ( buf . type  ===  UndoBuffer . bufferTypes . COLUMN )  { 
298-           min  =  buf . json . measureIndex ; 
296+           if  ( min  <  0 )  { 
297+             min  =  buf . json . measureIndex ; 
298+           }  else  { 
299+             min  =  Math . min ( min ,  buf . json . measureIndex ) ; 
300+           }           
299301          buf . json . measures . forEach ( ( mmjson : SmoMeasureParamsSer )  =>  { 
300302            max  =  Math . max ( max ,  mmjson . measureNumber . measureIndex ) ; 
301303          } ) ; 
302-           return  [ min ,  max ] ; 
303-         } 
304-         if  ( min  <  0 )  { 
305-           min  =  buf . selector . measure ; 
304+         }  else  { 
305+           if  ( min  <  0 )  { 
306+             min  =  buf . selector . measure ; 
307+           } 
308+           max  =  Math . max ( max ,  buf . selector . measure ) ; 
309+           min  =  Math . min ( min ,  buf . selector . measure ) ; 
306310        } 
307-         max  =  Math . max ( max ,  buf . selector . measure ) ; 
308-         min  =  Math . min ( min ,  buf . selector . measure ) ; 
309311      } 
310312    } 
311313    return  [ Math . max ( 0 ,  min ) ,  max ] ; 
@@ -336,8 +338,6 @@ export class UndoBuffer {
336338   * @returns   
337339   */ 
338340  undo ( score : SmoScore ,  staffMap : Record < number ,  number > ,  pop : boolean ) : SmoScore  { 
339-     let  i  =  0 ; 
340-     let  j  =  0 ; 
341341    let  mix  =  0 ; 
342342    let  bufset : UndoSet  |  null  =  this . popUndoSet ( ) ; 
343343    if  ( ! bufset )  { 
@@ -346,15 +346,15 @@ export class UndoBuffer {
346346    for  ( let  i  =  0 ;  i  <  bufset . buffers . length ;  ++ i )  { 
347347      const  buf  =  bufset . buffers [ bufset . buffers . length  -  ( i  +  1 ) ] ; 
348348      if  ( buf . type  ===  UndoBuffer . bufferTypes . RECTANGLE )  { 
349-         for  ( i   =  buf . json . topLeft . staff ;  i  <=  buf . json . bottomRight . staff ;  ++ i )  { 
350-           for  ( j   =  buf . json . topLeft . measure ;  j  <=  buf . json . bottomRight . measure ;  ++ j )  { 
349+         for  ( let   j   =  buf . json . topLeft . staff ;  j  <=  buf . json . bottomRight . staff ;  ++ j )  { 
350+           for  ( let   k   =  buf . json . topLeft . measure ;  k  <=  buf . json . bottomRight . measure ;  ++ k )  { 
351351            const  measure  =  SmoMeasure . deserialize ( buf . json . measures [ mix ] ) ; 
352352            mix  +=  1 ; 
353353            const  selector  =  SmoSelector . default ; 
354-             if  ( typeof ( staffMap [ i ] )  ===  'number' )  { 
355-               selector . staff  =  staffMap [ i ] ; 
356-               measure . measureNumber . staffId  =  staffMap [ i ] ; 
357-               selector . measure  =  j ; 
354+             if  ( typeof ( staffMap [ j ] )  ===  'number' )  { 
355+               selector . staff  =  staffMap [ j ] ; 
356+               measure . measureNumber . staffId  =  staffMap [ j ] ; 
357+               selector . measure  =  k ; 
358358              score . replaceMeasure ( selector ,  measure ) ; 
359359            } 
360360          } 
@@ -380,12 +380,12 @@ export class UndoBuffer {
380380      }  else  if  ( buf . type  ===  UndoBuffer . bufferTypes . SCORE_ATTRIBUTES )  { 
381381        smoSerialize . serializedMerge ( SmoScore . preferences ,  buf . json ,  score ) ; 
382382      }  else  if  ( buf . type  ===  UndoBuffer . bufferTypes . COLUMN )  { 
383-         for  ( i   =  0 ;  i  <  score . staves . length ;  ++ i )  { 
384-           const  measure  =  SmoMeasure . deserialize ( buf . json . measures [ i ] ) ; 
383+         for  ( let   j   =  0 ;  j  <  score . staves . length ;  ++ j )  { 
384+           const  measure  =  SmoMeasure . deserialize ( buf . json . measures [ j ] ) ; 
385385          const  selector  =  SmoSelector . default ; 
386-           if  ( typeof ( staffMap [ i ] )  ===  'number' )  { 
387-             selector . staff  =  staffMap [ i ] ; 
388-             measure . measureNumber . staffId  =  staffMap [ i ] ; 
386+           if  ( typeof ( staffMap [ j ] )  ===  'number' )  { 
387+             selector . staff  =  staffMap [ j ] ; 
388+             measure . measureNumber . staffId  =  staffMap [ j ] ; 
389389            selector . measure  =  buf . json . measureIndex ; 
390390            score . replaceMeasure ( selector ,  measure ) ; 
391391          } 
0 commit comments