@@ -129,6 +129,9 @@ private static void UpdateLogStyleFixedHeights()
129129
130130 Vector2 m_TextScroll = Vector2 . zero ;
131131
132+ int m_LastActiveEntryIndex = - 1 ;
133+ bool m_RestoreLatestSelection ;
134+
132135 //Make sure the minimum height of the panels can accomodate the cpmplete scroll bar icons
133136 SplitterState spl = SplitterState . FromRelative ( new float [ ] { 70 , 30 } , new float [ ] { 60 , 60 } , null ) ;
134137
@@ -557,7 +560,10 @@ internal void OnGUI()
557560 bool setErrorFlag = GUILayout . Toggle ( HasFlag ( ConsoleFlags . LogLevelError ) , new GUIContent ( ( errorCount <= 999 ? errorCount . ToString ( ) : "999+" ) , errorCount > 0 ? iconErrorSmall : iconErrorMono ) , Constants . MiniButtonRight ) ;
558561 // Active entry index may no longer be valid
559562 if ( EditorGUI . EndChangeCheck ( ) )
563+ {
560564 SetActiveEntry ( null ) ;
565+ m_LastActiveEntryIndex = - 1 ;
566+ }
561567
562568 SetFlag ( ConsoleFlags . LogLevelLog , setLogFlag ) ;
563569 SetFlag ( ConsoleFlags . LogLevelWarning , setWarningFlag ) ;
@@ -578,11 +584,27 @@ internal void OnGUI()
578584 int selectedRow = - 1 ;
579585 bool openSelectedItem = false ;
580586 bool collapsed = HasFlag ( ConsoleFlags . Collapse ) ;
587+ float scrollPosY = m_ListView . scrollPos . y ;
588+
581589 foreach ( ListViewElement el in ListViewGUI . ListView ( m_ListView , ListViewOptions . wantsRowMultiSelection , Constants . Box ) )
582590 {
591+ // Destroy latest restore entry if needed
592+ if ( e . type == EventType . ScrollWheel || e . type == EventType . Used )
593+ DestroyLatestRestoreEntry ( ) ;
594+
595+ // Make sure that scrollPos.y is always up to date after restoring last entry
596+ if ( m_RestoreLatestSelection )
597+ {
598+ m_ListView . scrollPos . y = scrollPosY ;
599+ }
600+
583601 if ( e . type == EventType . MouseDown && e . button == 0 && el . position . Contains ( e . mousePosition ) )
584602 {
585603 selectedRow = m_ListView . row ;
604+ DestroyLatestRestoreEntry ( ) ;
605+ LogEntry entry = new LogEntry ( ) ;
606+ LogEntries . GetEntryInternal ( m_ListView . row , entry ) ;
607+ m_LastActiveEntryIndex = entry . globalLineIndex ;
586608 if ( e . clickCount == 2 )
587609 openSelectedItem = true ;
588610 }
@@ -663,21 +685,28 @@ internal void OnGUI()
663685 if ( m_ListView . totalRows == 0 || m_ListView . row >= m_ListView . totalRows || m_ListView . row < 0 )
664686 {
665687 if ( m_ActiveText . Length != 0 )
688+ {
666689 SetActiveEntry ( null ) ;
690+ DestroyLatestRestoreEntry ( ) ;
691+ }
667692 }
668693 else
669694 {
670695 LogEntry entry = new LogEntry ( ) ;
671696 LogEntries . GetEntryInternal ( m_ListView . row , entry ) ;
672697 SetActiveEntry ( entry ) ;
698+ m_LastActiveEntryIndex = entry . globalLineIndex ;
699+
673700
674701 // see if selected entry changed. if so - clear additional info
675702 LogEntries . GetEntryInternal ( m_ListView . row , entry ) ;
676703 if ( m_ListView . selectionChanged || ! m_ActiveText . Equals ( entry . message ) )
677704 {
678705 SetActiveEntry ( entry ) ;
706+ m_LastActiveEntryIndex = entry . globalLineIndex ;
679707 }
680708
709+
681710 // If copy, get the messages from selected rows
682711 if ( e . type == EventType . ExecuteCommand && e . commandName == EventCommandNames . Copy && m_ListView . selectedItems != null )
683712 {
@@ -751,13 +780,16 @@ private void SearchField(Event e)
751780 }
752781
753782 string searchText = m_SearchText ;
783+
754784 if ( e . type == EventType . KeyDown )
755785 {
756786 if ( e . keyCode == KeyCode . Escape )
757787 {
758788 searchText = string . Empty ;
759789 GUIUtility . keyboardControl = m_ListView . ID ;
760790 Repaint ( ) ;
791+ if ( ! String . IsNullOrEmpty ( m_SearchText ) )
792+ RestoreLastActiveEntry ( ) ;
761793 }
762794 else if ( ( e . keyCode == KeyCode . UpArrow || e . keyCode == KeyCode . DownArrow ) &&
763795 GUI . GetNameOfFocusedControl ( ) == searchBarName )
@@ -941,6 +973,7 @@ private void AddStackTraceLoggingMenu(GenericMenu menu)
941973
942974 private void SetFilter ( string filteringText )
943975 {
976+ m_RestoreLatestSelection = String . IsNullOrEmpty ( filteringText ) && ! String . IsNullOrEmpty ( m_SearchText ) && m_LastActiveEntryIndex != - 1 ;
944977 if ( filteringText == null )
945978 {
946979 m_SearchText = "" ;
@@ -951,7 +984,38 @@ private void SetFilter(string filteringText)
951984 m_SearchText = filteringText ;
952985 LogEntries . SetFilteringText ( filteringText ) ; // Reset the active entry when we change the filtering text
953986 }
954- SetActiveEntry ( null ) ;
987+
988+ if ( m_RestoreLatestSelection )
989+ {
990+ RestoreLastActiveEntry ( ) ;
991+ }
992+ else
993+ {
994+ SetActiveEntry ( null ) ;
995+ DestroyLatestRestoreEntry ( ) ;
996+ }
997+ }
998+
999+ void RestoreLastActiveEntry ( )
1000+ {
1001+ int rowIndex = LogEntries . GetEntryRowIndex ( m_LastActiveEntryIndex ) ;
1002+ if ( rowIndex != - 1 )
1003+ {
1004+ ShowConsoleRow ( rowIndex ) ;
1005+ m_ListView . selectedItems = new bool [ rowIndex + 1 ] ;
1006+ m_ListView . selectedItems [ rowIndex ] = true ;
1007+ m_ListView . scrollPos . y = rowIndex * m_ListView . rowHeight ;
1008+ }
1009+ else
1010+ {
1011+ SetActiveEntry ( null ) ;
1012+ }
1013+ }
1014+
1015+ void DestroyLatestRestoreEntry ( )
1016+ {
1017+ m_LastActiveEntryIndex = - 1 ;
1018+ m_RestoreLatestSelection = false ;
9551019 }
9561020
9571021 [ UsedImplicitly ] private static event EntryDoubleClickedDelegate entryWithManagedCallbackDoubleClicked ;
0 commit comments