Fix the fucking first and last index selection logic

This commit is contained in:
2025-08-31 20:35:39 +02:00
parent c4e9007f2b
commit 0e3f2005d1
2 changed files with 54 additions and 32 deletions

View File

@@ -19,20 +19,25 @@ namespace DD2Switcher {
public static void UntrackWindow(int index) {
if (index >= 0 && index < NumProc) {
windows[index] = null;
// Compact the array by shifting non-null elements to the left
for (int i = index; i < NumProc - 1; i++) {
windows[i] = windows[i + 1];
}
windows[NumProc - 1] = null;
// Update ActiveIndex if needed
if (ActiveIndex == index) {
ActiveIndex = -1;
} else if (ActiveIndex > index) {
ActiveIndex--;
}
// Update first/last indices if needed
if (FirstIndex == index) {
FirstIndex = -1;
}
if (LastIndex == index) {
LastIndex = -1;
}
}
}
// Static properties for first/last selection persistence
public static int FirstIndex { get; set; } = -1;
public static int LastIndex { get; set; } = -1;
private static int ActiveIndex = -1;
private static bool AltPressed = false;