@@ -274,14 +274,14 @@ function showMessageScroller(msg) {
274274 } ) ;
275275}
276276
277- function showMessageScroller2 ( msg , initAtEndOfMsg , persist , alreadyProcessed ) {
277+ function showMessageScroller2 ( msg , persist , initAtEndOfMsg , alreadyProcessed ) {
278278 if ( initAtEndOfMsg === undefined ) { initAtEndOfMsg = false ; }
279279 if ( persist === undefined ) { persist = true ; }
280- if ( ! ! alreadyProcessed ) {
281- alreadyProcessed = { lines : [ ] , idxSpan : [ ] } ;
282- //alreadyProcessed.lines = [];
283- //alreadyProcessed.idxSpan = [];
284- }
280+ // if (!!alreadyProcessed) {
281+ // alreadyProcessed = { lines : [], startIdx : undefined, stopIdx : undefined };
282+ //}
283+
284+ print ( alreadyProcessed ) ;
285285
286286 if ( replying ) { return ; }
287287 if ( persist ) {
@@ -291,20 +291,28 @@ function showMessageScroller2(msg, initAtEndOfMsg, persist, alreadyProcessed) {
291291 }
292292
293293 let msgIdx = MESSAGES . findIndex ( ( m ) => m . id == msg . id )
294- //print("msgIdx",msgIdx);
294+ print ( "msgIdx" , msgIdx ) ;
295+ print ( msg ) ;
296+
297+ let cacheObj = { } ;
298+
295299 let startIdx = 0 ;
296300 let stopIdx = 0 ;
297301
298- if ( alreadyProcessed . idxSpan . length === 0 ) {
302+ if ( alreadyProcessed === undefined ) {
299303 startIdx = Math . max ( msgIdx - 1 , 0 ) ;
300304 stopIdx = Math . min ( msgIdx + 2 , MESSAGES . length ) ;
301- } else if ( msgIdx < alreadyProcessed . startIdx ) {
302- startIdx = Math . max ( msgIdx , 0 ) ;
305+ cacheObj = Object . assign ( { startIdx :startIdx , stopIdx :stopIdx } )
306+ } else if ( msgIdx <= alreadyProcessed . startIdx ) {
307+ startIdx = Math . max ( msgIdx - 1 , 0 ) ;
303308 stopIdx = alreadyProcessed . startIdx ;
304- } else if ( msgid >= alreadyProcessed . stopIdx ) {
309+ cacheObj = Object . assign ( { startIdx :startIdx , stopIdx :alreadyProcessed . stopIdx } )
310+ } else if ( msgIdx >= alreadyProcessed . stopIdx - 1 ) {
305311 startIdx = alreadyProcessed . stopIdx ;
306- stopIdx = Math . min ( msgIdx , MESSAGES . length ) ;
312+ stopIdx = Math . min ( msgIdx + 2 , MESSAGES . length ) ;
313+ cacheObj = Object . assign ( { startIdx :alreadyProcessed . startIdx , stopIdx :stopIdx } )
307314 }
315+ print ( startIdx , stopIdx ) ;
308316
309317 active = "scroller" ;
310318 var bodyFont = fontBig ;
@@ -342,14 +350,24 @@ function showMessageScroller2(msg, initAtEndOfMsg, persist, alreadyProcessed) {
342350 for ( let i = 0 ; i < messagesWrapped . length ; i ++ ) {
343351 allLines2 = allLines2 . concat ( messagesWrapped [ i ] ) ;
344352 }
345- var initScroll = messagesWrapped [ 0 ] . length ;
346- if ( msgIdx == 0 ) initScroll = 0 ;
347- if ( ! ! initAtEndOfMsg ) {
348- let i = msgIdx == 0 ?0 :1 ;
349- initScroll += messagesWrapped [ i ] . length > 8 ?messagesWrapped [ i ] . length - 8 :0 ;
353+
354+ if ( alreadyProcessed === undefined ) {
355+ // no-op
356+ } else if ( msgIdx <= alreadyProcessed . startIdx ) {
357+ allLines2 = allLines2 . concat ( alreadyProcessed . lines ) ;
358+ } else if ( msgIdx >= alreadyProcessed . stopIdx - 1 ) {
359+ allLines2 = alreadyProcessed . lines . concat ( allLines2 ) ;
350360 }
351361
352- if ( allLines2 . length == 0 && alreadyProcessed . idxSpan . length == 0 ) {
362+ // var initScroll = messagesWrapped[0].length;
363+ // if (msgIdx==0) initScroll = 0;
364+ // if (!!initAtEndOfMsg) {
365+ // let i = msgIdx==0?0:1;
366+ // initScroll += messagesWrapped[i].length>8?messagesWrapped[i].length-8:0;
367+ // }
368+ var initScroll = 10 ;
369+
370+ if ( allLines2 . length == 0 && alreadyProcessed . lines . length == 0 ) {
353371 cancelReloadTimeout ( ) ;
354372 returnToClockIfEmpty ( ) ;
355373 }
@@ -359,13 +377,13 @@ function showMessageScroller2(msg, initAtEndOfMsg, persist, alreadyProcessed) {
359377 //print("allLines2:\n",allLines2);
360378 //print("messagesWrapped:\n",messagesWrapped);
361379
362- let cacheObj = {
380+ cacheObj = Object . assign (
381+ {
363382 lines : allLines2 ,
364- startIdx : Math . min ( startIdx , alreadyProcessed . startIdx ) ,
365- stopIdx : Math . max ( stopIdx , alreadyProcessed . stopIdx ) ,
366383 titleLines : titleLines ,
367384 messagesWrappedLength : messagesWrapped . length ,
368- } ;
385+ } , cacheObj
386+ )
369387
370388 E . showScroller ( {
371389 scroll : initScroll * g . getFontHeight ( ) ,
@@ -381,12 +399,12 @@ function showMessageScroller2(msg, initAtEndOfMsg, persist, alreadyProcessed) {
381399 g . setFont ( bodyFont ) . setFontAlign ( 0 , - 1 ) . drawString ( allLines2 [ idx ] , r . x + r . w / 2 , r . y ) ;
382400 if ( idx >= allLines2 . length - 1 && msgIdx < MESSAGES . length - 1 ) {
383401 setTimeout ( ( ) => {
384- showMessageScroller2 ( MESSAGES [ msgIdx + 1 ] , true , cacheObj ) ;
402+ showMessageScroller2 ( MESSAGES [ msgIdx + 1 ] , true , true , cacheObj ) ;
385403 } , 0 )
386404 }
387405 if ( idx == 0 && msgIdx > 0 ) {
388406 setTimeout ( ( ) => {
389- showMessageScroller2 ( MESSAGES [ msgIdx - 1 ] , false , cacheObj ) ;
407+ showMessageScroller2 ( MESSAGES [ msgIdx - 1 ] , true , false , cacheObj ) ;
390408 } , 0 )
391409 }
392410 } , select : function ( idx , touch ) {
0 commit comments