Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 14759f3

Browse files
committed
Update detection of stickie items.
1 parent 6d8f9e1 commit 14759f3

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/GitHub.Exports.Reactive/Collections/TrackingCollection.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public static ObservableCollection<T> CreateListenerCollection<T>(this ITracking
8080

8181
var stickieItems = new[] { stickieItemOnTop };
8282
var result = new ObservableCollection<T>(tcol);
83-
var addedStickieItem = false;
8483
var hasSelection = false;
8584

8685
tcol.CollectionChanged += (_, e) =>
@@ -90,22 +89,24 @@ public static ObservableCollection<T> CreateListenerCollection<T>(this ITracking
9089

9190
selection.Subscribe(x =>
9291
{
92+
var hasStickieItem = result.FirstOrDefault() == stickieItemOnTop;
93+
9394
if (x == null || object.Equals(x, stickieItemOnTop))
9495
{
95-
if (addedStickieItem)
96+
if (hasStickieItem)
9697
{
9798
result.Remove(stickieItemOnTop);
98-
addedStickieItem = false;
99+
hasStickieItem = false;
99100
}
100101

101102
hasSelection = false;
102103
}
103104
else
104105
{
105-
if (!addedStickieItem)
106+
if (!hasStickieItem)
106107
{
107108
result.Insert(0, stickieItemOnTop);
108-
addedStickieItem = true;
109+
hasStickieItem = true;
109110
}
110111

111112
hasSelection = true;
@@ -123,11 +124,8 @@ static void UpdateStickieItems<T>(
123124
var offset = 0;
124125
if (stickieItemsOnTop != null)
125126
{
126-
foreach (var item in stickieItemsOnTop)
127-
{
128-
if (col.Contains(item))
129-
offset++;
130-
}
127+
if (object.Equals(col.FirstOrDefault(), stickieItemsOnTop.FirstOrDefault()))
128+
offset = stickieItemsOnTop.Count;
131129
}
132130

133131
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move)

0 commit comments

Comments
 (0)