From 933e0a66306b7bd53d67f48834cb7f56f5cd8d1b Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Thu, 04 Jun 2026 15:16:41 +0800
Subject: [PATCH] fix quick switch shelf badges and space labels

---
 C1.source/Sources/AlignerCore/Windows/QuickSwitchViewModel.swift |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/C1.source/Sources/AlignerCore/Windows/QuickSwitchViewModel.swift b/C1.source/Sources/AlignerCore/Windows/QuickSwitchViewModel.swift
index 49adc7b..1686294 100644
--- a/C1.source/Sources/AlignerCore/Windows/QuickSwitchViewModel.swift
+++ b/C1.source/Sources/AlignerCore/Windows/QuickSwitchViewModel.swift
@@ -208,8 +208,11 @@
         appCountsBySpace: [UInt64: Int],
         appNamesBySpace: [UInt64: [String]]
     ) -> [QuickSwitchDisplayViewModel] {
-        displays
+        let sortedDisplays = displays
             .sorted { $0.uuid.localizedStandardCompare($1.uuid) == .orderedAscending }
+        let displayCount = sortedDisplays.count
+
+        return sortedDisplays
             .enumerated()
             .map { displayIndex, display in
                 let displayLabel = displayLabel(for: displayIndex)
@@ -220,7 +223,7 @@
                             id: space.id,
                             displayUUID: space.displayUUID,
                             index: space.index,
-                            label: "\(displayLabel)\(space.index)",
+                            label: spaceLabel(for: space, displayIndex: displayIndex, displayCount: displayCount),
                             type: space.type,
                             isCurrent: currentSpaceIDs.contains(space.id),
                             windowCount: windowCountsBySpace[space.id] ?? 0,
@@ -256,14 +259,13 @@
 
     private static func labelsBySpaceID(from displays: [AlignerDisplay]) -> [UInt64: String] {
         var labels: [UInt64: String] = [:]
-
-        for (displayIndex, display) in displays
+        let sortedDisplays = displays
             .sorted(by: { $0.uuid.localizedStandardCompare($1.uuid) == .orderedAscending })
-            .enumerated()
-        {
-            let displayLabel = displayLabel(for: displayIndex)
+        let displayCount = sortedDisplays.count
+
+        for (displayIndex, display) in sortedDisplays.enumerated() {
             for space in display.spaces {
-                labels[space.id] = "\(displayLabel)\(space.index)"
+                labels[space.id] = spaceLabel(for: space, displayIndex: displayIndex, displayCount: displayCount)
             }
         }
 
@@ -328,4 +330,12 @@
 
         return String(String.UnicodeScalarView(scalars))
     }
+
+    private static func spaceLabel(for space: AlignerSpace, displayIndex: Int, displayCount: Int) -> String {
+        if displayCount <= 1 {
+            return String(format: "%02d", space.index)
+        }
+
+        return "\(displayLabel(for: displayIndex))\(space.index)"
+    }
 }

--
Gitblit v1.9.3