From eea933f5b841dd686efb87ccef16d34f3f346c62 Mon Sep 17 00:00:00 2001 From: Nick Wolff Date: Wed, 21 Oct 2026 23:55:54 -0400 Subject: [PATCH] fix(settings): make drag-to-reorder rows work - Replace onMove, which macOS ignores outside a List, with onDrag/onDrop so settings rows reorder as they're dragged - Apply to menu bar modules and dashboard sections --- App/Settings/DashboardPane.swift | 3 +- App/Settings/MenuBarPane.swift | 8 ++-- App/Settings/SettingsComponents.swift | 66 +++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/App/Settings/DashboardPane.swift b/App/Settings/DashboardPane.swift index 14508a6..5e2b243 100644 --- a/App/Settings/DashboardPane.swift +++ b/App/Settings/DashboardPane.swift @@ -6,6 +6,7 @@ import SwiftUI struct DashboardPane: View { @Bindable var preferences: Preferences + @State private var draggedSection: DashboardSection? var body: some View { Form { @@ -35,11 +36,11 @@ struct DashboardPane: View { ) } .toggleStyle(.switch) + .reorderable(section, in: order, dragging: $draggedSection, move: preferences.moveDashboardSections) .contextMenu { MoveCommands(index: index, count: order.count, move: preferences.moveDashboardSections) } } - .onMove(perform: preferences.moveDashboardSections) } header: { Text("Sections") } footer: { diff --git a/App/Settings/MenuBarPane.swift b/App/Settings/MenuBarPane.swift index bb30306..6e2e71a 100644 --- a/App/Settings/MenuBarPane.swift +++ b/App/Settings/MenuBarPane.swift @@ -7,6 +7,7 @@ import SwiftUI struct MenuBarPane: View { @Bindable var preferences: Preferences let statusItems: StatusItemController + @State private var draggedModule: MenuBarModule? var body: some View { Form { @@ -52,7 +53,9 @@ struct MenuBarPane: View { .toggleStyle(.switch) // The last module that's always shown stays so there's always an item to click. .disabled(!selection.isAvailable(module) || !selection.canHide(module)) - .moveDisabled(!isMovable) + .reorderable(module, in: selection.order, dragging: $draggedModule, isEnabled: isMovable) { source, destination in + preferences.menuBarModules.move(fromOffsets: source, toOffset: destination) + } .contextMenu { if isMovable { MoveCommands(index: index, count: selection.order.count) { source, destination in @@ -61,9 +64,6 @@ struct MenuBarPane: View { } } } - .onMove { source, destination in - preferences.menuBarModules.move(fromOffsets: source, toOffset: destination) - } } header: { Text("Modules") } footer: { diff --git a/App/Settings/SettingsComponents.swift b/App/Settings/SettingsComponents.swift index 2ca809c..683c12c 100644 --- a/App/Settings/SettingsComponents.swift +++ b/App/Settings/SettingsComponents.swift @@ -92,6 +92,72 @@ struct MoveCommands: View { } } +extension View { + /// Drag-to-reorder for a row in a `Form`, where `onMove` does nothing on macOS. + /// Rows move live as the dragged one passes over them. + func reorderable( + _ item: Item, + in order: [Item], + dragging: Binding, + isEnabled: Bool = true, + move: @escaping (IndexSet, Int) -> Void + ) -> some View { + modifier(Reorderable(item: item, order: order, dragging: dragging, isEnabled: isEnabled, move: move)) + } +} + +private struct Reorderable: ViewModifier { + let item: Item + let order: [Item] + @Binding var dragging: Item? + let isEnabled: Bool + let move: (IndexSet, Int) -> Void + + func body(content: Content) -> some View { + if isEnabled { + content + .onDrag { + dragging = item + return NSItemProvider(object: String(describing: item) as NSString) + } + .onDrop(of: [.text], delegate: ReorderDropDelegate(item: item, order: order, dragging: $dragging, move: move)) + } else { + content + } + } +} + +private struct ReorderDropDelegate: DropDelegate { + let item: Item + let order: [Item] + @Binding var dragging: Item? + let move: (IndexSet, Int) -> Void + + func validateDrop(info: DropInfo) -> Bool { + dragging != nil + } + + func dropEntered(info: DropInfo) { + guard let dragging, dragging != item, + let source = order.firstIndex(of: dragging), + let target = order.firstIndex(of: item) + else { return } + // `onMove` offsets: landing below a row means inserting after it. + withAnimation { + move([source], target > source ? target + 1 : target) + } + } + + func dropUpdated(info: DropInfo) -> DropProposal? { + DropProposal(operation: .move) + } + + func performDrop(info: DropInfo) -> Bool { + dragging = nil + return true + } +} + extension MenuBarModule { var symbol: String { switch self {