@@ -146,6 +146,7 @@ class GPasteApplet extends Applet.IconApplet {
146146 this . _appletSettings . bind ( "display-searchbar" , "displaySearchBar" , this . _onDisplaySettingsUpdated ) ;
147147 this . _appletSettings . bind ( "display-gpaste-ui" , "displayGPasteUI" , this . _onDisplaySettingsUpdated ) ;
148148 this . _appletSettings . bind ( "display-empty-history" , "displayEmptyHistory" , this . _onDisplaySettingsUpdated ) ;
149+ this . _appletSettings . bind ( "reverse-history-order" , "reverseHistory" , this . _onDisplaySettingsUpdated ) ;
149150
150151 this . _appletSettings . bind ( "kb-show-history" , "kbShowHistory" , this . _onKeybindingUpdated ) ;
151152 this . _onKeybindingUpdated ( ) ;
@@ -254,6 +255,9 @@ class GPasteApplet extends Applet.IconApplet {
254255
255256 this . msepBottom2 . actor . visible = this . displayGPasteUI ;
256257 this . mitemUI . actor . visible = this . displayGPasteUI ;
258+
259+ // any change to these settings may require re-rendering the history
260+ this . _onSettingsUpdated ( ) ;
257261 }
258262
259263 /*
@@ -273,10 +277,6 @@ class GPasteApplet extends Applet.IconApplet {
273277 }
274278 }
275279
276- if ( this . mitemSearch . entry . get_text ( ) == '' ) {
277- this . _historyItems [ 0 ] . actor . set_style ( "font-weight: bold;" ) ;
278- }
279-
280280 this . refresh ( oldSize ) ;
281281 }
282282
@@ -352,6 +352,9 @@ class GPasteApplet extends Applet.IconApplet {
352352 * Refresh the history items
353353 */
354354 refresh ( startID ) {
355+ // clear any previous styling before we repopulate
356+ this . _historyItems . forEach ( item => item . actor . set_style ( null ) ) ;
357+
355358 if ( this . _searchResults . length > 0 ) { // Search field isn't empty
356359 this . search ( this . mitemSearch . getText ( ) ) ;
357360 } else {
@@ -364,7 +367,9 @@ class GPasteApplet extends Applet.IconApplet {
364367 }
365368
366369 for ( let i = startID ; i < size ; ++ i ) {
367- this . _historyItems [ i ] . setIndex ( i ) ;
370+ // if reverseHistory is enabled we flip the index we ask for
371+ const idx = this . reverseHistory ? ( size - 1 - i ) : i ;
372+ this . _historyItems [ i ] . setIndex ( idx ) ;
368373 }
369374 for ( let i = size ; i < maxSize ; ++ i ) {
370375 this . _historyItems [ i ] . setIndex ( - 1 ) ;
@@ -374,6 +379,10 @@ class GPasteApplet extends Applet.IconApplet {
374379 this . mitemHistoryIsEmpty . actor . show ( ) ;
375380 } else {
376381 this . mitemHistoryIsEmpty . actor . hide ( ) ;
382+ // highlight the item that corresponds to the newest element
383+ const highlightPos = this . reverseHistory ? size - 1 : 0 ;
384+ if ( highlightPos >= 0 && highlightPos < this . _historyItems . length )
385+ this . _historyItems [ highlightPos ] . actor . set_style ( "font-weight: bold;" ) ;
377386 }
378387 } ) ;
379388 }
@@ -397,14 +406,18 @@ class GPasteApplet extends Applet.IconApplet {
397406 results = maxSize ;
398407 }
399408
409+ // if we're showing results in reverse order we should flip the array
410+ const ordered = this . reverseHistory ? this . _searchResults . slice ( ) . reverse ( ) : this . _searchResults ;
411+
400412 this . _historyItems . slice ( 0 , results ) . forEach ( ( item , index ) => {
401- item . setUuid ( this . _searchResults [ index ] ) ;
413+ item . setUuid ( ordered [ index ] ) ;
402414 } ) ;
403415 this . _historyItems . slice ( results , maxSize ) . forEach ( ( item , index ) => {
404416 item . setIndex ( - 1 ) ;
405417 } ) ;
406418
407- this . _historyItems [ 0 ] . actor . set_style ( null ) ;
419+ // clear styling from all items when searching
420+ this . _historyItems . forEach ( item => item . actor . set_style ( null ) ) ;
408421
409422 if ( results == 0 ) { // There aren't any results, display "(No results)"
410423 this . mitemNoSearchResults . actor . show ( ) ;
@@ -417,7 +430,6 @@ class GPasteApplet extends Applet.IconApplet {
417430
418431 this . _searchResults = [ ] ;
419432 this . refresh ( 0 ) ;
420- this . _historyItems [ 0 ] . actor . set_style ( "font-weight: bold;" ) ;
421433 }
422434 }
423435
@@ -572,6 +584,17 @@ class GPasteApplet extends Applet.IconApplet {
572584 this . mitemTrack . setToggleState ( state ) ;
573585 }
574586
587+ /*
588+ * Called whenever settings change that affect how the history is presented
589+ */
590+ _onSettingsUpdated ( ) {
591+ if ( this . _searchResults . length > 0 ) {
592+ this . search ( this . mitemSearch . getText ( ) ) ;
593+ } else {
594+ this . refresh ( 0 ) ;
595+ }
596+ }
597+
575598 //
576599 // Overrides
577600 // ---------------------------------------------------------------------------------
0 commit comments