Skip to content

Commit f9a1880

Browse files
committed
fix: correct action reordering in Actions tab
1 parent 2cff3ad commit f9a1880

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

Sources/Core/Actions/ActionRegistry.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public final class ActionRegistry: ObservableObject, Sendable {
8686
newActions.insert(contentsOf: movingActions, at: dest)
8787
actions = newActions
8888

89-
let newOrder = actions.map { $0.id }
89+
let newOrder = actions
90+
.filter { !ActionIdentity.isAIPreset($0) }
91+
.map { $0.id }
9092
settingsStore.set(.actionOrder, value: newOrder)
9193
}
9294

Sources/OpenClip/UI/Preferences/ActionsTabView.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,21 @@ struct ActionsTab: View {
131131
return (rowIndex, actionIndex)
132132
}
133133
let actionIndexByRow = Dictionary(uniqueKeysWithValues: actionIndices.map { ($0.rowIndex, $0.actionIndex) })
134-
let actionSource = IndexSet(source.compactMap { actionIndexByRow[$0] })
135-
let actionDestination = actionIndices.prefix { $0.rowIndex < destination }.count
134+
var actionSource = IndexSet(source.compactMap { actionIndexByRow[$0] })
135+
// Expand: if a group parent is being moved, include its sub-actions
136+
let sourceIDs = Set(actionSource.map { coordinator.actions[$0].id })
137+
for (index, action) in coordinator.actions.enumerated() {
138+
if sourceIDs.contains(where: { action.id.hasPrefix($0 + ".") }) {
139+
actionSource.insert(index)
140+
}
141+
}
142+
guard !actionSource.isEmpty else { return }
143+
let actionDestination: Int
144+
if let firstAtOrAfter = actionIndices.first(where: { $0.rowIndex >= destination }) {
145+
actionDestination = firstAtOrAfter.actionIndex
146+
} else {
147+
actionDestination = coordinator.actions.count
148+
}
136149
coordinator.moveActions(from: actionSource, to: actionDestination)
137150
}
138151

@@ -152,6 +165,7 @@ struct ActionsTab: View {
152165
case .packageHeader(let packageID, let title, let gatedReason):
153166
PackageHeaderRowView(packageID: packageID, title: title, gatedReason: gatedReason, disabledPackages: $disabledPackages)
154167
.tag(row.id)
168+
.moveDisabled(true)
155169
case .groupParent(let action):
156170
ActionRowView(
157171
action: action,

0 commit comments

Comments
 (0)