Ariver
2026-05-22 8478c55e513bbbb4b1676d1d9207f7feb2509465
Apptag/ContentView.swift
@@ -201,7 +201,6 @@
    let colorIndex: Int
    var dragModeActive: Bool = false
    var isDragging: Bool = false
    var dragResetToken: Int = 0
    let action: () -> Void
    private var bgColor: Color {
@@ -227,7 +226,6 @@
            .opacity(dragModeActive ? (isDragging ? 1.0 : 0.62) : 1.0)
            .animation(.easeOut(duration: 0.08), value: isDragging)
            .animation(.easeOut(duration: 0.08), value: dragModeActive)
            .id("\(name)|reset-\(dragResetToken)")
            .contentShape(RoundedRectangle(cornerRadius: 7))
            .onTapGesture {
                action()
@@ -242,7 +240,6 @@
    let colorIndex: Int
    var dragModeActive: Bool = false
    var isDragging: Bool = false
    var dragResetToken: Int = 0
    let action: () -> Void
    private var bgColor: Color {
@@ -264,7 +261,6 @@
            .opacity(dragModeActive ? (isDragging ? 1.0 : 0.62) : 1.0)
            .animation(.easeOut(duration: 0.08), value: isDragging)
            .animation(.easeOut(duration: 0.08), value: dragModeActive)
            .id("\(name)|reset-\(dragResetToken)")
            .contentShape(RoundedRectangle(cornerRadius: 6))
            .onTapGesture {
                action()
@@ -339,9 +335,17 @@
    let hideOverlay: () -> Void
    private let initialQuickSearchSource: String?
    @Environment(\.colorScheme) private var colorScheme
    @State private var allApps: [AppInfo] = []
    @State private var displayGroups: [TagGroup] = []
    @State private var tagColors: [String: Int] = [:]
    @State private var scrollProxy: ScrollViewProxy? = nil
    @StateObject private var scrollInteractionState = AppGridScrollInteractionState()
    @State private var groupLayoutVersion = 0
    @State private var cachedGridContainerRowsKey: GridContainerRowsKey? = nil
    @State private var cachedGridContainerRows: [GridContainerLayoutRow] = []
    @State private var appGridScrollTargetID: String? = nil
    @State private var appGridScrollRequestToken = 0
    // Edit mode
    @State private var editPhase: EditPhase = .none
@@ -355,7 +359,6 @@
    @State private var tagReorderFrames: [String: CGRect] = [:]
    @State private var tagNavDragModeActive = false
    @State private var tagNavDragItem: String? = nil
    @State private var tagNavDragResetToken = 0
    @State private var tagNavReorderFrames: [String: CGRect] = [:]
    @State private var tagNavReorderDidMove = false
    @State private var hoveredContainer: String? = nil  // colored container lift
@@ -370,7 +373,6 @@
    @State private var refreshInProgress = false
    @State private var refreshAgainAfterCurrent = false
    @State private var refreshAgainForceLayout = false
    @State private var hoveredAppItemID: String? = nil
    @State private var hoveredBubble: AppBubbleContext? = nil
    @State private var editingBubble: AppBubbleContext? = nil
    @State private var pendingUncategorizedDrop: PendingUncategorizedDrop? = nil
@@ -386,6 +388,7 @@
    @State private var quickSearchSelectedID: URL? = nil
    @State private var quickSearchManualSelection = false
    @State private var quickSearchFocusToken = 0
    @State private var quickSearchSelectionScrollToken = 0
    @State private var quickSearchCloseHidesOverlay = false
    @State private var quickSearchErrorMessage: String? = nil
    @State private var initialQuickSearchConsumed = false
@@ -407,15 +410,28 @@
    @State private var notchHeight: CGFloat = 0
    @AppStorage("displayMode") private var displayMode = AppDefaults.displayMode
    @AppStorage("hideAppNames") private var hideAppNames = AppDefaults.hideAppNames
    @AppStorage("showUncommonAppBubbles") private var showUncommonAppBubbles = AppDefaults.showUncommonAppBubbles
    private let editSidebarWidth: CGFloat = 188
    private let editSidebarHorizontalInset: CGFloat = 12
    private let floatingControlsTrailingInset: CGFloat = 20
    private let floatingControlsReservedWidth: CGFloat = 120
    private var appBubbleDisabled: Bool {
        appDragModeActive || pendingUncategorizedDrop != nil
        appDragModeActive || pendingUncategorizedDrop != nil || scrollInteractionState.isFrozen
    }
    private let rightSidebarFloatingClearance: CGFloat = 44
    private var cardSurfaceColor: Color {
        colorScheme == .dark
            ? Color.white.opacity(0.055)
            : Color.white.opacity(0.62)
    }
    private var floatingButtonSurfaceColor: Color {
        colorScheme == .dark
            ? Color.white.opacity(0.10)
            : Color.white.opacity(0.78)
    }
    private var isSideLayout: Bool {
        tagPosition == "left" || tagPosition == "right"
@@ -433,19 +449,19 @@
        displayMode == "coloredContainer" || displayMode == "coloredGridContainer"
    }
    private var quickSearchOnlyMode: Bool {
        quickSearchVisible && quickSearchCloseHidesOverlay
    private var usesAppKitContainerGrid: Bool {
        displayMode == "gridContainer" || displayMode == "coloredGridContainer"
    }
    var body: some View {
        ZStack {
            if !quickSearchOnlyMode {
            if !quickSearchVisible {
                VisualEffectView(material: .hudWindow, blendingMode: .behindWindow)
                    .ignoresSafeArea()
                    .allowsHitTesting(false)
            }
            if !quickSearchOnlyMode {
            if !quickSearchVisible {
                if notchHeight > 0 {
                    VStack {
                        Rectangle().fill(.black)
@@ -473,7 +489,7 @@
            quickSearchOverlay
            if !quickSearchOnlyMode, let message = dropWarningToast {
            if !quickSearchVisible, let message = dropWarningToast {
                Text(message)
                    .font(.system(size: 16, weight: .semibold))
                    .foregroundStyle(.primary)
@@ -488,7 +504,7 @@
                    .allowsHitTesting(false)
            }
            if !quickSearchOnlyMode && dropRefreshVisible {
            if !quickSearchVisible && dropRefreshVisible {
                Color.black.opacity(0.08)
                    .ignoresSafeArea()
                    .transition(.opacity)
@@ -510,12 +526,15 @@
        }
        .onAppear {
            refreshNotchHeight()
            refreshApps()
            refreshAppsIfNeeded()
            if let initialQuickSearchSource, !initialQuickSearchConsumed {
                initialQuickSearchConsumed = true
                quickSearchCloseHidesOverlay = initialQuickSearchSource == QuickSearchOpenSource.globalHidden
                quickSearchVisible = true
                quickSearchFocusToken &+= 1
                if !quickSearchVisible {
                    quickSearchVisible = true
                    quickSearchFocusToken &+= 1
                }
                refreshQuickSearchResults()
                NotificationCenter.default.post(
                    name: .tagLauncherQuickSearchVisibilityChanged,
                    object: nil,
@@ -526,7 +545,7 @@
        .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidShow)) { _ in
            resetTransientDragState()
            refreshNotchHeight()
            refreshApps()
            refreshAppsIfNeeded()
        }
        .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidHide)) { _ in
            resetTransientDragState()
@@ -568,6 +587,12 @@
            if editingBubble != nil && !focused {
                commitBubbleNote()
            }
        }
        .onChange(of: draggedTagNames) { _, newOrder in
            rebuildDisplayGroups(apps: allApps, tagOrder: newOrder)
        }
        .onChange(of: defaultGroupName) { _, _ in
            rebuildDisplayGroups(apps: allApps, tagOrder: draggedTagNames)
        }
        .onChange(of: quickSearchQuery) { _, _ in
            quickSearchErrorMessage = nil
@@ -613,11 +638,13 @@
    private var quickSearchOverlay: some View {
        GeometryReader { proxy in
            if quickSearchVisible {
                QuickSearchBackdropClickView {
                    closeQuickSearch()
                }
                Color.black.opacity(0.001)
                    .frame(width: proxy.size.width, height: proxy.size.height)
                    .ignoresSafeArea()
                    .contentShape(Rectangle())
                    .onTapGesture {
                        closeQuickSearch()
                    }
                    .zIndex(899)
                QuickSearchOverlayView(
@@ -625,6 +652,7 @@
                    results: quickSearchResults,
                    selectedID: quickSearchSelectedID,
                    focusToken: quickSearchFocusToken,
                    selectionScrollToken: quickSearchSelectionScrollToken,
                    isLoading: quickSearchDocuments.isEmpty && refreshInProgress,
                    maxVisibleRows: quickSearchMaxVisibleRows(in: proxy.size),
                    errorMessage: quickSearchErrorMessage,
@@ -756,9 +784,11 @@
        let nextIndex = min(max(currentIndex + delta, 0), quickSearchResults.count - 1)
        quickSearchSelectedID = quickSearchResults[nextIndex].id
        quickSearchManualSelection = true
        quickSearchSelectionScrollToken &+= 1
    }
    private func selectQuickSearchResult(_ result: QuickSearchResult) {
        guard quickSearchSelectedID != result.id || !quickSearchManualSelection else { return }
        quickSearchSelectedID = result.id
        quickSearchManualSelection = true
    }
@@ -819,7 +849,7 @@
    ) -> some View {
        NativeFloatingIconButton(systemImage: systemImage, action: action)
            .frame(width: 36, height: 36)
            .background(Circle().fill(.ultraThinMaterial))
            .background(Circle().fill(floatingButtonSurfaceColor))
    }
    // MARK: - Top / Side Layouts
@@ -852,7 +882,6 @@
                    TagPill(name: tag.name, colorIndex: tag.colorIndex,
                            dragModeActive: tagNavDragModeActive && canReorderTag(tag.name),
                            isDragging: tagNavDragItem == tag.name,
                            dragResetToken: tagNavDragResetToken,
                            action: {
                        activateTagNavigation(tag.id)
                    })
@@ -894,7 +923,6 @@
                    SideTagPill(name: tag.name, colorIndex: tag.colorIndex,
                                dragModeActive: tagNavDragModeActive && canReorderTag(tag.name),
                                isDragging: tagNavDragItem == tag.name,
                                dragResetToken: tagNavDragResetToken,
                                action: {
                        activateTagNavigation(tag.id)
                    })
@@ -927,8 +955,33 @@
                Spacer()
                ProgressView().scaleEffect(0.8)
                Spacer()
            } else if displayMode == "gridContainer" || displayMode == "coloredGridContainer" {
                gridContainerGrid
            } else if usesAppKitContainerGrid {
                AppGridCollectionView(
                    groups: displayGroups,
                    tagColors: tagColors,
                    displayMode: displayMode,
                    iconSize: iconSize,
                    showNames: !hideAppNames,
                    bubbleDisabled: appBubbleDisabled,
                    showUncommonAppBubbles: showUncommonAppBubbles,
                    highlightedGroupName: filledColorlessContainer,
                    contentRevision: groupLayoutVersion,
                    scrollTargetID: appGridScrollTargetID,
                    scrollRequestToken: appGridScrollRequestToken,
                    onSelectApp: { app in openApp(app) },
                    onBubbleHover: handleBubbleHover,
                    onEditNote: beginEditingBubbleNote,
                    onDropApp: { path, source, target, copy in
                        dropApp(path: path, sourceTag: source, targetTag: target, copy: copy)
                    },
                    onGroupActivate: { groupName in
                        if displayMode == "gridContainer" {
                            toggleColorlessFill(groupName)
                        }
                    },
                    onScrollActivity: handleAppGridScrollActivity,
                    onDragModeChange: { setAppDragMode($0) }
                )
            } else if displayMode == "container" || displayMode == "coloredContainer" {
                containerGrid
            } else {
@@ -1063,7 +1116,7 @@
        ScrollViewReader { proxy in
            ScrollView {
                LazyVStack(alignment: .leading, spacing: 24) {
                    ForEach(groups) { group in
                    ForEach(displayGroups) { group in
                        TagGroupView(
                            group: group,
                            onSelectApp: { app in openApp(app) },
@@ -1075,14 +1128,16 @@
                            onBubbleHover: handleBubbleHover,
                            onEditNote: beginEditingBubbleNote,
                            bubbleDisabled: appBubbleDisabled,
                            showUncommonAppBubbles: showUncommonAppBubbles,
                            dragResetToken: appDragResetToken,
                            hoveredAppItemID: $hoveredAppItemID,
                            onDropApp: { path, source, copy in
                                dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy)
                            }
                        ).id(group.id)
                    }
                }.padding(20)
                }
                .padding(20)
                .background(AppGridScrollActivityObserver(onScroll: handleAppGridScrollActivity))
            }
            .id(displayMode)  // force rebuild on mode switch
            .onAppear { scrollProxy = proxy }
@@ -1098,7 +1153,7 @@
            let colCount = max(1, Int((available + gap) / (colW + gap)))
            let actualColW = (available - gap * CGFloat(colCount - 1)) / CGFloat(colCount)
            let columns = distributeToColumns(groups: groups, colCount: colCount, colWidth: actualColW)
            let columns = distributeToColumns(groups: displayGroups, colCount: colCount, colWidth: actualColW)
            ScrollViewReader { proxy in
                ScrollView {
@@ -1113,6 +1168,7 @@
                        }
                    }
                    .padding(outerPad)
                    .background(AppGridScrollActivityObserver(onScroll: handleAppGridScrollActivity))
                }
                .id(displayMode)  // force rebuild on mode switch
                .onAppear { scrollProxy = proxy }
@@ -1180,9 +1236,9 @@
                        onBubbleHover: handleBubbleHover,
                        onEditNote: beginEditingBubbleNote,
                        bubbleDisabled: appBubbleDisabled,
                        showUncommonAppBubbles: showUncommonAppBubbles,
                        itemID: "\(group.name)|\(app.path.path)",
                        dragResetToken: appDragResetToken,
                        hoveredAppItemID: $hoveredAppItemID,
                        onSelect: { openApp(app) }
                    )
                }
@@ -1195,7 +1251,7 @@
                .fill((isColored || isColorlessActive) ? tagColor.opacity(0.30) : Color.clear)
                .background(
                    RoundedRectangle(cornerRadius: 14)
                        .fill(.ultraThinMaterial)
                        .fill(cardSurfaceColor)
                )
        )
        .overlay(
@@ -1203,10 +1259,12 @@
                .stroke(Color.primary.opacity(0.08), lineWidth: 1)
        )
        .overlay {
            AppDropTargetView(targetTag: group.name) { path, source, copy in
                dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy)
            if appDragModeActive {
                AppDropTargetView(targetTag: group.name) { path, source, copy in
                    dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy)
                }
                .allowsHitTesting(false)
            }
            .allowsHitTesting(false)
        }
        .shadow(color: .black.opacity((isColored && isHovered) || isColorlessActive ? 0.22 : 0),
                radius: (isColored && isHovered) || isColorlessActive ? 8 : 0,
@@ -1214,11 +1272,17 @@
        .zIndex(isHovered ? 50 : 0)
        .animation(.easeOut(duration: 0.045), value: isHovered)
        .animation(.easeOut(duration: 0.08), value: isColorlessFilled)
        .onHover { hovering in
        .background(AppHoverTrackingView { hovering, _ in
            guard !scrollInteractionState.isFrozen else {
                if !hovering && hoveredContainer == group.name {
                    hoveredContainer = nil
                }
                return
            }
            if isColored || isColorless {
                hoveredContainer = hovering ? group.name : nil
            }
        }
        })
        .contentShape(RoundedRectangle(cornerRadius: 14))
        .onTapGesture {
            if isColorless {
@@ -1236,11 +1300,23 @@
            let gap: CGFloat = 16
            let available = geo.size.width - outerPad * 2
            let preferredCount = preferredGridContainersPerRow(availableWidth: available)
            let rows = gridContainerRows(groups: groups, trackCount: preferredCount, availableWidth: available, gap: gap)
            let rowsKey = GridContainerRowsKey(
                groupLayoutVersion: groupLayoutVersion,
                trackCount: preferredCount,
                availableWidth: Int(available.rounded()),
                iconSize: Int(iconSize.rounded())
            )
            let rows = gridContainerRowsForRender(
                key: rowsKey,
                groups: displayGroups,
                trackCount: preferredCount,
                availableWidth: available,
                gap: gap
            )
            ScrollViewReader { proxy in
                ScrollView {
                    VStack(alignment: .leading, spacing: gap) {
                    LazyVStack(alignment: .leading, spacing: gap) {
                        ForEach(Array(rows.indices), id: \.self) { rowIndex in
                            let row = rows[rowIndex]
@@ -1255,9 +1331,28 @@
                    }
                    .padding(outerPad)
                    .frame(maxWidth: .infinity, alignment: .topLeading)
                    .background(AppGridScrollActivityObserver(onScroll: handleAppGridScrollActivity))
                }
                .id(displayMode)
                .onAppear { scrollProxy = proxy }
                .onAppear {
                    updateCachedGridContainerRows(
                        key: rowsKey,
                        groups: displayGroups,
                        trackCount: preferredCount,
                        availableWidth: available,
                        gap: gap
                    )
                }
                .onChange(of: rowsKey) { _, newKey in
                    updateCachedGridContainerRows(
                        key: newKey,
                        groups: displayGroups,
                        trackCount: preferredCount,
                        availableWidth: available,
                        gap: gap
                    )
                }
            }
        }
    }
@@ -1279,10 +1374,52 @@
        let fixedRows: Int
    }
    private struct GridContainerRowsKey: Equatable {
        let groupLayoutVersion: Int
        let trackCount: Int
        let availableWidth: Int
        let iconSize: Int
    }
    private struct GridContainerCandidate {
        let spans: [Int]
        let rows: Int
        let cost: CGFloat
    }
    private func gridContainerRowsForRender(
        key: GridContainerRowsKey,
        groups: [TagGroup],
        trackCount: Int,
        availableWidth: CGFloat,
        gap: CGFloat
    ) -> [GridContainerLayoutRow] {
        if cachedGridContainerRowsKey == key {
            return cachedGridContainerRows
        }
        return gridContainerRows(
            groups: groups,
            trackCount: trackCount,
            availableWidth: availableWidth,
            gap: gap
        )
    }
    private func updateCachedGridContainerRows(
        key: GridContainerRowsKey,
        groups: [TagGroup],
        trackCount: Int,
        availableWidth: CGFloat,
        gap: CGFloat
    ) {
        guard cachedGridContainerRowsKey != key else { return }
        cachedGridContainerRows = gridContainerRows(
            groups: groups,
            trackCount: trackCount,
            availableWidth: availableWidth,
            gap: gap
        )
        cachedGridContainerRowsKey = key
    }
    private func gridContainerRows(groups: [TagGroup], trackCount: Int, availableWidth: CGFloat, gap: CGFloat) -> [GridContainerLayoutRow] {
@@ -1420,9 +1557,9 @@
                                onBubbleHover: handleBubbleHover,
                                onEditNote: beginEditingBubbleNote,
                                bubbleDisabled: appBubbleDisabled,
                                showUncommonAppBubbles: showUncommonAppBubbles,
                                itemID: "\(group.name)|\(app.path.path)",
                                dragResetToken: appDragResetToken,
                                hoveredAppItemID: $hoveredAppItemID,
                                onSelect: { openApp(app) }
                            )
                                .frame(width: cellWidth)
@@ -1447,7 +1584,7 @@
                .fill((isColored || isColorlessGridActive) ? tagColor.opacity(0.30) : Color.clear)
                .background(
                    RoundedRectangle(cornerRadius: 14)
                        .fill(.ultraThinMaterial)
                        .fill(cardSurfaceColor)
                )
        )
        .overlay(
@@ -1455,10 +1592,12 @@
                .stroke(Color.primary.opacity(0.08), lineWidth: 1)
        )
        .overlay {
            AppDropTargetView(targetTag: group.name) { path, source, copy in
                dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy)
            if appDragModeActive {
                AppDropTargetView(targetTag: group.name) { path, source, copy in
                    dropApp(path: path, sourceTag: source, targetTag: group.name, copy: copy)
                }
                .allowsHitTesting(false)
            }
            .allowsHitTesting(false)
        }
        .shadow(color: .black.opacity((isColored && isHovered) || isColorlessGridActive ? 0.22 : 0),
                radius: (isColored && isHovered) || isColorlessGridActive ? 8 : 0,
@@ -1466,13 +1605,19 @@
        .zIndex(isHovered ? 50 : 0)
        .animation(.easeOut(duration: 0.045), value: isHovered)
        .animation(.easeOut(duration: 0.08), value: isColorlessFilled)
        .onHover { hovering in
        .background(AppHoverTrackingView { hovering, _ in
            guard !scrollInteractionState.isFrozen else {
                if !hovering && hoveredContainer == group.name {
                    hoveredContainer = nil
                }
                return
            }
            if isColored || isColorlessGrid {
                hoveredContainer = hovering ? group.name : nil
            } else if hovering {
                fillColorlessContainer(group.name)
            }
        }
        })
        .contentShape(RoundedRectangle(cornerRadius: 14))
        .onTapGesture {
            if isColorlessGrid {
@@ -1993,14 +2138,20 @@
            let result = SmartStartService.applySuggestion(draft)
            let store = result.store
            let apps = TagEditor.annotate(apps: scannedApps, store: store)
            let quickSearchDocs = QuickSearchEngine.makeDocuments(apps: apps, store: store)
            let colors = store.tags.mapValues { $0.color }
            let order = TagEditor.orderedTagNames()
            DispatchQueue.main.async {
                pendingSmartStartDraft = nil
                allApps = apps
                quickSearchDocuments = quickSearchDocs
                tagColors = colors
                draggedTagNames = order
                rebuildDisplayGroups(apps: apps, tagOrder: order)
                if quickSearchVisible {
                    refreshQuickSearchResults()
                }
                if let summary = result.summary {
                    showSmartStartNotice(mode: .manuallyApplied, summary: summary)
                } else {
@@ -2059,17 +2210,10 @@
        tagName == TagDatabase.uncommonTagKey ? tr("group.uncommon") : tagName
    }
    private var tagLabels: [TagLabel] {
        groups.map { TagLabel(name: $0.name, colorIndex: tagColors[$0.name] ?? 0) }
    }
    private var groups: [TagGroup] {
        let order = draggedTagNames.isEmpty
            ? TagEditor.orderedTagNames()
            : draggedTagNames
        let raw = AppIndexer.group(apps: allApps, defaultGroupName: defaultGroupName, tagOrder: order)
        // Translate stable keys for display
        return raw.map { group in
    private func makeDisplayGroups(apps: [AppInfo], tagOrder: [String]) -> [TagGroup] {
        let order = tagOrder.isEmpty ? TagEditor.orderedTagNames() : tagOrder
        let rawGroups = AppIndexer.group(apps: apps, defaultGroupName: defaultGroupName, tagOrder: order)
        return rawGroups.map { group in
            if group.name == defaultGroupName {
                return TagGroup(name: tr("group.uncategorized"), apps: group.apps)
            }
@@ -2080,8 +2224,18 @@
        }
    }
    private func rebuildDisplayGroups(apps: [AppInfo], tagOrder: [String]) {
        displayGroups = makeDisplayGroups(apps: apps, tagOrder: tagOrder)
        groupLayoutVersion &+= 1
        cachedGridContainerRowsKey = nil
    }
    private var tagLabels: [TagLabel] {
        displayGroups.map { TagLabel(name: $0.name, colorIndex: tagColors[$0.name] ?? 0) }
    }
    private var editGroups: [TagGroup] {
        groups + [
        displayGroups + [
            TagGroup(
                name: tr("group.uncommon"),
                apps: allApps.filter(\.isUncommon).sorted {
@@ -2093,12 +2247,25 @@
    // MARK: - Actions
    private func refreshAppsIfNeeded() {
        guard allApps.isEmpty, !refreshInProgress else { return }
        refreshApps()
    }
    private func refreshNotchHeight() {
        let mousePoint = NSEvent.mouseLocation
        let activeScreen = NSScreen.screens.first(where: {
            NSMouseInRect(mousePoint, $0.frame, false)
        }) ?? NSScreen.main
        notchHeight = activeScreen?.safeAreaInsets.top ?? 0
    }
    private func handleAppGridScrollActivity() {
        if !scrollInteractionState.isFrozen {
            hoveredBubble = nil
            hoveredContainer = nil
        }
        scrollInteractionState.noteScroll()
    }
    private func handleBubbleHover(app: AppInfo, frame: CGRect, event: AppBubbleHoverEvent) {
@@ -2156,13 +2323,16 @@
    }
    private func clearAppBubbleState() {
        hoveredAppItemID = nil
        hoveredBubble = nil
        if hoveredBubble != nil {
            hoveredBubble = nil
        }
        if editingBubble != nil {
            notifyAppNoteEditing(active: false)
            editingBubble = nil
        }
        editingBubble = nil
        bubbleNoteFocused = false
        if bubbleNoteFocused {
            bubbleNoteFocused = false
        }
    }
    private func notifyAppNoteEditing(active: Bool) {
@@ -2226,7 +2396,12 @@
    }
    func scrollTo(_ id: String) {
        withAnimation(.easeInOut(duration: 0.25)) { scrollProxy?.scrollTo(id, anchor: .top) }
        if usesAppKitContainerGrid {
            appGridScrollTargetID = id
            appGridScrollRequestToken &+= 1
        } else {
            withAnimation(.easeInOut(duration: 0.25)) { scrollProxy?.scrollTo(id, anchor: .top) }
        }
    }
    private func activateTagNavigation(_ id: String) {
@@ -2297,13 +2472,14 @@
    }
    private func endTagNavReorder() {
        let hadDragState = tagNavDragModeActive || tagNavDragItem != nil
        guard hadDragState else { return }
        if tagNavDragModeActive && tagNavReorderDidMove {
            TagEditor.reorderTags(draggedTagNames)
        }
        tagNavDragModeActive = false
        tagNavDragItem = nil
        tagNavReorderDidMove = false
        tagNavDragResetToken &+= 1
    }
    private func cancelTagNavReorderVisualState() {
@@ -2311,7 +2487,6 @@
        tagNavDragModeActive = false
        tagNavDragItem = nil
        tagNavReorderDidMove = false
        tagNavDragResetToken &+= 1
    }
    private func reorderTagNavItem(at location: CGPoint) {
@@ -2482,6 +2657,7 @@
    }
    private func setAppDragMode(_ active: Bool) {
        guard appDragModeActive != active else { return }
        if active {
            endTagNavReorder()
            clearAppBubbleState()
@@ -2489,7 +2665,7 @@
        appDragModeActive = active
        if active {
            DispatchQueue.main.asyncAfter(deadline: .now() + 8) {
                if appDragModeActive {
                if appDragModeActive && !AppDragCoordinator.shared.hasActiveDrag {
                    appDragModeActive = false
                }
            }
@@ -2497,18 +2673,32 @@
    }
    private func resetTransientDragState(keepingPendingUncategorizedDrop: Bool = false) {
        let hadAppDragState = appDragModeActive
        AppDragCoordinator.shared.cancelDrag()
        appDragModeActive = false
        appDragResetToken &+= 1
        tagNavDragModeActive = false
        tagNavDragItem = nil
        tagNavReorderDidMove = false
        tagNavDragResetToken &+= 1
        dragItem = nil
        hoveredAppItemID = nil
        hoveredContainer = nil
        scrollInteractionState.reset()
        if appDragModeActive {
            appDragModeActive = false
        }
        if hadAppDragState {
            appDragResetToken &+= 1
        }
        if tagNavDragModeActive {
            tagNavDragModeActive = false
        }
        if tagNavDragItem != nil {
            tagNavDragItem = nil
        }
        if tagNavReorderDidMove {
            tagNavReorderDidMove = false
        }
        if dragItem != nil {
            dragItem = nil
        }
        if hoveredContainer != nil {
            hoveredContainer = nil
        }
        clearAppBubbleState()
        if !keepingPendingUncategorizedDrop {
        if !keepingPendingUncategorizedDrop, pendingUncategorizedDrop != nil {
            pendingUncategorizedDrop = nil
        }
    }
@@ -2540,6 +2730,7 @@
                quickSearchDocuments = quickSearchDocs
                tagColors = colors
                draggedTagNames = order
                rebuildDisplayGroups(apps: apps, tagOrder: order)
                if quickSearchVisible {
                    refreshQuickSearchResults()
                }
@@ -2592,6 +2783,134 @@
    }
}
private final class AppGridScrollInteractionState: ObservableObject {
    @Published var isFrozen = false
    private var unfreezeWorkItem: DispatchWorkItem?
    func noteScroll() {
        if !isFrozen {
            isFrozen = true
        }
        unfreezeWorkItem?.cancel()
        let workItem = DispatchWorkItem { [weak self] in
            guard let self, self.isFrozen else { return }
            self.isFrozen = false
        }
        unfreezeWorkItem = workItem
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.18, execute: workItem)
    }
    func reset() {
        unfreezeWorkItem?.cancel()
        unfreezeWorkItem = nil
        if isFrozen {
            isFrozen = false
        }
    }
}
private struct AppGridScrollActivityObserver: NSViewRepresentable {
    let onScroll: () -> Void
    func makeCoordinator() -> Coordinator {
        Coordinator(onScroll: onScroll)
    }
    func makeNSView(context: Context) -> ScrollActivityNSView {
        let view = ScrollActivityNSView()
        view.coordinator = context.coordinator
        return view
    }
    func updateNSView(_ view: ScrollActivityNSView, context: Context) {
        context.coordinator.onScroll = onScroll
        view.coordinator = context.coordinator
    }
    final class Coordinator {
        var onScroll: () -> Void
        private weak var observedClipView: NSClipView?
        private var observer: NSObjectProtocol?
        private var lastReportedBoundsOrigin: NSPoint?
        init(onScroll: @escaping () -> Void) {
            self.onScroll = onScroll
        }
        func install(from view: NSView) {
            guard let clipView = view.enclosingScrollView?.contentView else { return }
            guard observedClipView !== clipView else { return }
            removeObserver()
            observedClipView = clipView
            lastReportedBoundsOrigin = clipView.bounds.origin
            clipView.postsBoundsChangedNotifications = true
            observer = NotificationCenter.default.addObserver(
                forName: NSView.boundsDidChangeNotification,
                object: clipView,
                queue: .main
            ) { [weak self, weak clipView] _ in
                guard let self,
                      let clipView,
                      self.recordScrollIfNeeded(from: clipView)
                else { return }
                self.onScroll()
            }
        }
        private func removeObserver() {
            if let observer {
                NotificationCenter.default.removeObserver(observer)
            }
            observer = nil
            observedClipView = nil
            lastReportedBoundsOrigin = nil
        }
        private func recordScrollIfNeeded(from clipView: NSClipView) -> Bool {
            let origin = clipView.bounds.origin
            guard let last = lastReportedBoundsOrigin else {
                lastReportedBoundsOrigin = origin
                return false
            }
            let didScroll = abs(origin.x - last.x) > 0.5
                || abs(origin.y - last.y) > 0.5
            if didScroll {
                lastReportedBoundsOrigin = origin
            }
            return didScroll
        }
        deinit {
            removeObserver()
        }
    }
    final class ScrollActivityNSView: NSView {
        weak var coordinator: Coordinator?
        private var installScheduled = false
        override func viewDidMoveToWindow() {
            super.viewDidMoveToWindow()
            installObserverIfPossible()
        }
        override func viewDidMoveToSuperview() {
            super.viewDidMoveToSuperview()
            installObserverIfPossible()
        }
        func installObserverIfPossible() {
            guard !installScheduled else { return }
            installScheduled = true
            DispatchQueue.main.async { [weak self] in
                guard let self else { return }
                installScheduled = false
                coordinator?.install(from: self)
            }
        }
    }
}
// MARK: - Tag Label
private struct TagReorderFramePreferenceKey: PreferenceKey {