Open History to see the last commit
1import SwiftUI
2
3struct FeatureComposerCommandPopover: View {
4 let triggerKind: FeatureComposerTriggerKind
5 let items: [FeatureComposerMenuItem]
6 let isLoading: Bool
7 let errorMessage: String?
8 let pathSearchAvailable: Bool
9 let onSelect: (FeatureComposerMenuItem) -> Void
10
11 var body: some View {
12 VStack(alignment: .leading, spacing: 0) {
13 if items.isEmpty {
14 Text(emptyMessage)
15 .font(T3Typography.supporting)
16 .foregroundStyle(T3Colors.textSecondary)
17 .frame(maxWidth: .infinity, alignment: .leading)
18 .padding(.horizontal, 14)
19 .padding(.vertical, 12)
20 } else {
21 ScrollView {
22 LazyVStack(spacing: 0) {
23 ForEach(Array(items.enumerated()), id: \.element.id) { index, item in
24 Button {
25 onSelect(item)
26 } label: {
27 FeatureComposerCommandRow(item: item, triggerKind: triggerKind)
28 }
29 .buttonStyle(.plain)
30 .accessibilityLabel(accessibilityLabel(for: item))
31 .accessibilityIdentifier("composer-suggestion-\(item.id)")
32
33 if index < items.count - 1 {
34 Divider()
35 .overlay(T3Colors.separator)
36 .padding(.leading, 40)
37 }
38 }
39 }
40 }
41 .scrollIndicators(.hidden)
42 }
43 }
44 .frame(height: menuHeight, alignment: .top)
45 .background(T3Colors.surfaceRaised.opacity(0.98))
46 .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
47 .overlay {
48 RoundedRectangle(cornerRadius: 12, style: .continuous)
49 .stroke(T3Colors.border, lineWidth: 1)
50 }
51 .accessibilityLabel(groupLabel)
52 .accessibilityIdentifier("composer-command-menu")
53 }
54
55 private var groupLabel: String {
56 switch triggerKind {
57 case .slashCommand: return "Commands"
58 case .model: return "Models"
59 case .skill: return "Skills"
60 case .path: return "Files"
61 }
62 }
63
64 private var emptyMessage: String {
65 if isLoading { return "Searching files…" }
66 if let errorMessage, !errorMessage.isEmpty { return errorMessage }
67 switch triggerKind {
68 case .slashCommand: return "No matching commands"
69 case .model: return "No matching models"
70 case .skill: return "No matching skills"
71 case .path where !pathSearchAvailable: return "File search unavailable"
72 case .path: return "Type a file name"
73 }
74 }
75
76 private func accessibilityLabel(for item: FeatureComposerMenuItem) -> String {
77 item.description.isEmpty ? item.label : "\(item.label), \(item.description)"
78 }
79
80 private var menuHeight: CGFloat {
81 Self.height(forItemCount: items.count)
82 }
83
84 /// The menu's height is deterministic so the composer can position the
85 /// menu fully above its own surface without measuring it.
86 static func height(forItemCount count: Int) -> CGFloat {
87 guard count > 0 else { return 48 }
88 let rowHeight: CGFloat = 47
89 return min(CGFloat(count) * rowHeight, 188)
90 }
91}
92
93private struct FeatureComposerCommandRow: View {
94 let item: FeatureComposerMenuItem
95 let triggerKind: FeatureComposerTriggerKind
96
97 var body: some View {
98 HStack(spacing: 10) {
99 Image(systemName: iconName)
100 .font(.system(size: 14, weight: .medium))
101 .foregroundStyle(T3Colors.textTertiary)
102 .frame(width: 17)
103
104 Text(displayLabel)
105 .font(T3Typography.control)
106 .foregroundStyle(T3Colors.textPrimary)
107 .lineLimit(1)
108 .layoutPriority(1)
109
110 if !item.description.isEmpty {
111 Text(item.description)
112 .font(T3Typography.supporting)
113 .foregroundStyle(T3Colors.textTertiary)
114 .lineLimit(1)
115 .frame(maxWidth: .infinity, alignment: .leading)
116 } else {
117 Spacer(minLength: 0)
118 }
119 }
120 .padding(.horizontal, 14)
121 .frame(minHeight: 46)
122 .contentShape(Rectangle())
123 }
124
125 private var iconName: String {
126 switch item {
127 case .modelCommand, .model: return "cpu"
128 case .providerCommand: return "terminal"
129 case let .skill(skill): return skill.source.systemImage
130 case let .path(entry): return entry.kind == .directory ? "folder" : "doc"
131 }
132 }
133
134 private var displayLabel: String {
135 if triggerKind == .slashCommand, case let .skill(skill) = item {
136 return "/skill:\(skill.displayName ?? skill.name)"
137 }
138 return item.label
139 }
140}