Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(infra): add `List` extension method for shifting a value to a specified index

Lars Berger2dd5db0e7368
diff --git a/GlazeWM.Infrastructure/Utils/ListExtensions.cs b/GlazeWM.Infrastructure/Utils/ListExtensions.cs
index 0b69e7b4..b1d1c992 100644
--- a/GlazeWM.Infrastructure/Utils/ListExtensions.cs
+++ b/GlazeWM.Infrastructure/Utils/ListExtensions.cs
@@ -16,16 +16,24 @@ namespace GlazeWM.Infrastructure.Utils
}
/// <summary>
- /// Shift a value to the first index of a list. Insert at start if it doesn't already exist.
+ /// Shift a value to a specified index in a list. Insert at index if it doesn't already exist.
/// </summary>
- public static void MoveToFront<T>(this IList<T> source, T value)
+ public static void ShiftToIndex<T>(this IList<T> source, int index, T value)
{
var initialIndex = source.IndexOf(value);
if (initialIndex != -1)
source.Remove(value);
- source.Insert(0, value);
+ source.Insert(index, value);
+ }
+
+ /// <summary>
+ /// Shift a value to the first index of a list. Insert at start if it doesn't already exist.
+ /// </summary>
+ public static void MoveToFront<T>(this IList<T> source, T value)
+ {
+ ShiftToIndex(source, 0, value);
}
}
}