Skip to content

Commit 137dd36

Browse files
committed
Selected log entry is preserved after filtering the logs if the entry is in the list of filtered logs (closed #91)
1 parent d118c81 commit 137dd36

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

Plugins/IngameDebugConsole/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= In-game Debug Console (v1.6.9) =
1+
= In-game Debug Console (v1.7.0) =
22

33
Documentation: https://github.com/yasirkula/UnityIngameDebugConsole
44
FAQ: https://github.com/yasirkula/UnityIngameDebugConsole#faq

Plugins/IngameDebugConsole/Scripts/DebugLogManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,6 @@ private void CollapseButtonPressed()
14421442
// Swap the value of collapse mode
14431443
isCollapseOn = !isCollapseOn;
14441444

1445-
SnapToBottom = true;
14461445
collapseButton.color = isCollapseOn ? collapseButtonSelectedColor : collapseButtonNormalColor;
14471446
recycledListView.SetCollapseMode( isCollapseOn );
14481447

@@ -1684,6 +1683,7 @@ internal void Resize( PointerEventData eventData )
16841683
// Determine the filtered list of debug entries to show on screen
16851684
private void FilterLogs()
16861685
{
1686+
recycledListView.OnBeforeFilterLogs();
16871687
logEntriesToShow.Clear();
16881688

16891689
if( timestampsOfLogEntriesToShow != null )
@@ -1757,7 +1757,7 @@ private void FilterLogs()
17571757
}
17581758

17591759
// Update the recycled list view
1760-
recycledListView.DeselectSelectedLogItem();
1760+
recycledListView.OnAfterFilterLogs();
17611761
OnLogEntriesUpdated( true, true );
17621762
}
17631763

Plugins/IngameDebugConsole/Scripts/DebugLogRecycledListView.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public class DebugLogRecycledListView : MonoBehaviour
3636
private float heightOfSelectedLogEntry;
3737
private float DeltaHeightOfSelectedLogEntry { get { return heightOfSelectedLogEntry - logItemHeight; } }
3838

39+
/// These properties are used by <see cref="OnBeforeFilterLogs"/> and <see cref="OnAfterFilterLogs"/>.
40+
private int collapsedOrderOfSelectedLogEntry;
41+
private float scrollDistanceToSelectedLogEntry;
42+
3943
// Log items used to visualize the visible debug entries
4044
private readonly DynamicCircularBuffer<DebugLogItem> visibleLogItems = new DynamicCircularBuffer<DebugLogItem>( 32 );
4145

@@ -128,6 +132,57 @@ public void DeselectSelectedLogItem()
128132
heightOfSelectedLogEntry = 0f;
129133
}
130134

135+
/// <summary>
136+
/// Cache the currently selected log item's properties so that its position can be restored after <see cref="OnAfterFilterLogs"/> is called.
137+
/// </summary>
138+
public void OnBeforeFilterLogs()
139+
{
140+
collapsedOrderOfSelectedLogEntry = 0;
141+
scrollDistanceToSelectedLogEntry = 0f;
142+
143+
if( selectedLogEntry != null )
144+
{
145+
if( !isCollapseOn )
146+
{
147+
for( int i = 0; i < indexOfSelectedLogEntry; i++ )
148+
{
149+
if( entriesToShow[i] == selectedLogEntry )
150+
collapsedOrderOfSelectedLogEntry++;
151+
}
152+
}
153+
154+
scrollDistanceToSelectedLogEntry = indexOfSelectedLogEntry * ItemHeight - transformComponent.anchoredPosition.y;
155+
}
156+
}
157+
158+
/// <summary>
159+
/// See <see cref="OnBeforeFilterLogs"/>.
160+
/// </summary>
161+
public void OnAfterFilterLogs()
162+
{
163+
// Refresh selected log entry's index
164+
int newIndexOfSelectedLogEntry = -1;
165+
if( selectedLogEntry != null )
166+
{
167+
for( int i = 0; i < entriesToShow.Count; i++ )
168+
{
169+
if( entriesToShow[i] == selectedLogEntry && collapsedOrderOfSelectedLogEntry-- == 0 )
170+
{
171+
newIndexOfSelectedLogEntry = i;
172+
break;
173+
}
174+
}
175+
}
176+
177+
if( newIndexOfSelectedLogEntry < 0 )
178+
DeselectSelectedLogItem();
179+
else
180+
{
181+
indexOfSelectedLogEntry = newIndexOfSelectedLogEntry;
182+
transformComponent.anchoredPosition = new Vector2( 0f, newIndexOfSelectedLogEntry * ItemHeight - scrollDistanceToSelectedLogEntry );
183+
}
184+
}
185+
131186
// Number of debug entries may have changed, update the list
132187
public void OnLogEntriesUpdated( bool updateAllVisibleItemContents )
133188
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.ingamedebugconsole",
33
"displayName": "In-game Debug Console",
4-
"version": "1.6.9",
4+
"version": "1.7.0",
55
"documentationUrl": "https://github.com/yasirkula/UnityIngameDebugConsole",
66
"changelogUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)