Skip to content

armgit / chops

Public Imported from GitHub
0

Your AI agent skills, finally organized. A macOS app to browse, edit, and manage skills across Claude Code, Cursor, Codex, Windsurf, and Amp.

fix: resolve infinite SwiftUI layout loop when selecting a skill (#28)

Khan Wange05494dbb099
diff --git a/Chops/App/ChopsApp.swift b/Chops/App/ChopsApp.swift
index 9eebd93..51e9bbb 100644
--- a/Chops/App/ChopsApp.swift
+++ b/Chops/App/ChopsApp.swift
@@ -26,8 +26,6 @@ struct ChopsApp: App {
}
}()
- @FocusedValue(\.saveAction) var saveAction
-
var body: some Scene {
WindowGroup {
ContentView()
@@ -37,10 +35,10 @@ struct ChopsApp: App {
.commands {
CommandGroup(replacing: .saveItem) {
Button("Save") {
- saveAction?.action()
+ NotificationCenter.default.post(name: .saveCurrentSkill, object: nil)
}
.keyboardShortcut("s", modifiers: .command)
- .disabled(saveAction == nil)
+ .disabled(appState.selectedSkill == nil)
}
CommandGroup(after: .appInfo) {
CheckForUpdatesView(updater: updaterController.updater)
diff --git a/Chops/Views/Detail/SkillDetailView.swift b/Chops/Views/Detail/SkillDetailView.swift
index 672bed3..4bc18a6 100644
--- a/Chops/Views/Detail/SkillDetailView.swift
+++ b/Chops/Views/Detail/SkillDetailView.swift
@@ -44,7 +44,9 @@ struct SkillDetailView: View {
.onChange(of: skill.filePath) {
document.load(from: skill)
}
- .focusedValue(\.saveAction, SaveAction(action: { document.save(to: skill) }))
+ .onReceive(NotificationCenter.default.publisher(for: .saveCurrentSkill)) { _ in
+ document.save(to: skill)
+ }
.alert("Save Error", isPresented: $document.showingSaveError) {
Button("OK") {}
} message: {
diff --git a/Chops/Views/Detail/SkillEditorView.swift b/Chops/Views/Detail/SkillEditorView.swift
index 86285ad..deed9f1 100644
--- a/Chops/Views/Detail/SkillEditorView.swift
+++ b/Chops/Views/Detail/SkillEditorView.swift
@@ -225,21 +225,10 @@ struct SkillEditorView: View {
}
}
-// MARK: - Save Action via FocusedValues for Cmd+S menu support
+// MARK: - Save notification for Cmd+S menu support
-struct SaveAction {
- let action: () -> Void
-}
-
-struct SaveActionKey: FocusedValueKey {
- typealias Value = SaveAction
-}
-
-extension FocusedValues {
- var saveAction: SaveAction? {
- get { self[SaveActionKey.self] }
- set { self[SaveActionKey.self] = newValue }
- }
+extension Notification.Name {
+ static let saveCurrentSkill = Notification.Name("saveCurrentSkill")
}
// MARK: - Syntax-highlighted NSTextView wrapper
@@ -312,7 +301,6 @@ struct HighlightedTextEditor: NSViewRepresentable {
enum MarkdownHighlighter {
private static let muted = NSColor.secondaryLabelColor
private static let faintBg = NSColor.quaternaryLabelColor
-
static func highlight(_ textView: NSTextView) {
let text = textView.string
let fullRange = NSRange(location: 0, length: (text as NSString).length)