Skip to content

Commit f3bb9cc

Browse files
committed
Support reordering and adjust styles
1 parent 461f2bc commit f3bb9cc

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

Copilot for Xcode/CustomCommandView.swift

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,29 @@ struct CustomCommandView: View {
8080
List {
8181
ForEach(settings.customCommands, id: \.name) { command in
8282
HStack {
83-
Text(command.name)
83+
Image(systemName: "line.3.horizontal")
8484

85-
Spacer()
85+
HStack {
86+
Text(command.name)
8687

87-
Group {
88-
switch command.feature {
89-
case .chatWithSelection:
90-
Text("Chat with Selection")
91-
case .customChat:
92-
Text("Custom Chat")
93-
case .promptToCode:
94-
Text("Prompt to Code")
88+
Spacer()
89+
90+
Group {
91+
switch command.feature {
92+
case .chatWithSelection:
93+
Text("Chat with Selection")
94+
case .customChat:
95+
Text("Custom Chat")
96+
case .promptToCode:
97+
Text("Prompt to Code")
98+
}
9599
}
100+
.foregroundStyle(.tertiary)
101+
}
102+
.contentShape(Rectangle())
103+
.onTapGesture {
104+
editingCommand = .init(isNew: false, command: command)
96105
}
97-
.foregroundStyle(.tertiary)
98-
}
99-
.contentShape(Rectangle())
100-
.onTapGesture {
101-
editingCommand = .init(isNew: false, command: command)
102106
}
103107
.contextMenu {
104108
Button("Remove") {
@@ -108,6 +112,9 @@ struct CustomCommandView: View {
108112
}
109113
}
110114
}
115+
.onMove(perform: { indices, newOffset in
116+
settings.customCommands.move(fromOffsets: indices, toOffset: newOffset)
117+
})
111118
}
112119
.overlay {
113120
if settings.customCommands.isEmpty {
@@ -159,23 +166,23 @@ struct EditCustomCommandView: View {
159166
case let .chatWithSelection(prompt):
160167
commandType = .chatWithSelection
161168
self.prompt = prompt ?? ""
162-
self.systemPrompt = ""
163-
self.continuousMode = false
169+
systemPrompt = ""
170+
continuousMode = false
164171
case let .customChat(systemPrompt, prompt):
165172
commandType = .customChat
166173
self.systemPrompt = systemPrompt ?? ""
167174
self.prompt = prompt ?? ""
168-
self.continuousMode = false
175+
continuousMode = false
169176
case let .promptToCode(prompt, continuousMode):
170177
commandType = .promptToCode
171178
self.prompt = prompt ?? ""
172-
self.systemPrompt = ""
179+
systemPrompt = ""
173180
self.continuousMode = continuousMode ?? false
174181
case .none:
175182
commandType = .chatWithSelection
176-
self.prompt = ""
177-
self.systemPrompt = ""
178-
self.continuousMode = false
183+
prompt = ""
184+
systemPrompt = ""
185+
continuousMode = false
179186
}
180187
}
181188

@@ -210,7 +217,7 @@ struct EditCustomCommandView: View {
210217
promptTextField
211218
}
212219
}
213-
220+
214221
Text(
215222
"After renaming or adding a custom command, please restart Xcode to refresh the menu."
216223
)
@@ -285,13 +292,23 @@ struct EditCustomCommandView: View {
285292
}
286293

287294
var promptTextField: some View {
288-
TextField("Prompt", text: $prompt)
289-
.lineLimit(0)
295+
if #available(macOS 13.0, *) {
296+
return TextField("Prompt", text: $prompt, axis: .vertical)
297+
.multilineTextAlignment(.leading)
298+
.lineLimit(4, reservesSpace: true)
299+
} else {
300+
return TextField("Prompt", text: $prompt)
301+
}
290302
}
291303

292304
var systemPromptTextField: some View {
293-
TextField("System Prompt", text: $systemPrompt)
294-
.lineLimit(0)
305+
if #available(macOS 13.0, *) {
306+
return TextField("System Prompt", text: $systemPrompt, axis: .vertical)
307+
.multilineTextAlignment(.leading)
308+
.lineLimit(4, reservesSpace: true)
309+
} else {
310+
return TextField("Prompt", text: $prompt)
311+
}
295312
}
296313

297314
var continuousModeToggle: some View {

0 commit comments

Comments
 (0)