Skip to content

Commit b41691d

Browse files
committed
Merge branch 'feature/window-related-shortcuts' into develop
2 parents ef67329 + 6017ac6 commit b41691d

5 files changed

Lines changed: 66 additions & 26 deletions

File tree

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ struct ChatWindowView: View {
2323
Group {
2424
if let chat = viewModel.chat {
2525
ChatPanel(chat: chat)
26+
.background {
27+
Button(action: {
28+
viewModel.isPanelDisplayed = false
29+
}) {
30+
EmptyView()
31+
}
32+
.keyboardShortcut("M", modifiers: [.command])
33+
}
2634
}
2735
}
2836
.opacity(viewModel.isPanelDisplayed ? 1 : 0)

Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ struct ChatPanelToolbar: View {
3333

3434
var body: some View {
3535
HStack {
36-
Toggle(isOn: .init(get: {
37-
useGlobalChat
38-
}, set: { _ in
39-
chat.switchContext()
40-
})) { EmptyView() }
41-
.toggleStyle(GlobalChatSwitchToggleStyle())
42-
43-
Spacer()
44-
4536
Button(action: {
4637
chat.close()
4738
}) {
@@ -50,17 +41,27 @@ struct ChatPanelToolbar: View {
5041
.foregroundStyle(.secondary)
5142
}
5243
.buttonStyle(.plain)
44+
.keyboardShortcut("w", modifiers: [.command])
45+
46+
Spacer()
47+
48+
Toggle(isOn: .init(get: {
49+
useGlobalChat
50+
}, set: { _ in
51+
chat.switchContext()
52+
})) { EmptyView() }
53+
.toggleStyle(GlobalChatSwitchToggleStyle())
5354
}
54-
.padding(.leading, 8)
55-
.padding(.trailing, 4)
55+
.padding(.leading, 4)
56+
.padding(.trailing, 8)
5657
.padding(.vertical, 4)
5758
.background(.regularMaterial)
5859
}
5960
}
6061

6162
struct ChatPanelMessages: View {
6263
@ObservedObject var chat: ChatProvider
63-
64+
6465
var body: some View {
6566
List {
6667
Group {
@@ -287,12 +288,6 @@ struct ChatPanelInputArea: View {
287288
.multilineTextAlignment(.leading)
288289
.textFieldStyle(.plain)
289290
.padding(8)
290-
.onSubmit {
291-
if chat.isReceivingMessage { return }
292-
if typedMessage.isEmpty { return }
293-
chat.send(typedMessage)
294-
typedMessage = ""
295-
}
296291

297292
Button(action: {
298293
if typedMessage.isEmpty { return }
@@ -304,6 +299,7 @@ struct ChatPanelInputArea: View {
304299
}
305300
.buttonStyle(.plain)
306301
.disabled(chat.isReceivingMessage)
302+
.keyboardShortcut(KeyEquivalent.return, modifiers: [])
307303
}
308304
.frame(maxWidth: .infinity)
309305
.background {
@@ -314,6 +310,14 @@ struct ChatPanelInputArea: View {
314310
RoundedRectangle(cornerRadius: 6)
315311
.stroke(Color(nsColor: .controlColor), lineWidth: 1)
316312
}
313+
.background {
314+
Button(action: {
315+
typedMessage += "\n"
316+
}) {
317+
EmptyView()
318+
}
319+
.keyboardShortcut(KeyEquivalent.return, modifiers: [.shift])
320+
}
317321
}
318322
.onAppear {
319323
isInputAreaFocused = true
@@ -535,3 +539,4 @@ struct ChatPanel_Light_Preview: PreviewProvider {
535539
.colorScheme(.light)
536540
}
537541
}
542+

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ struct PromptToCodePanel: View {
5959
provider.cancel()
6060
}) {
6161
Text("Cancel")
62-
}.buttonStyle(CommandButtonStyle(color: .gray))
62+
}
63+
.buttonStyle(CommandButtonStyle(color: .gray))
64+
.keyboardShortcut("w", modifiers: [.command])
6365

6466
if !provider.code.isEmpty {
6567
Button(action: {
@@ -149,7 +151,7 @@ struct PromptToCodePanelContent: View {
149151
.frame(maxWidth: .infinity)
150152
.scaleEffect(x: -1, y: -1, anchor: .center)
151153
}
152-
154+
153155
if let name = provider.name {
154156
Text(name)
155157
.font(.footnote)
@@ -204,9 +206,6 @@ struct PromptToCodePanelToolbar: View {
204206
.multilineTextAlignment(.leading)
205207
.textFieldStyle(.plain)
206208
.padding(8)
207-
.onSubmit {
208-
provider.sendRequirement()
209-
}
210209

211210
Button(action: {
212211
provider.sendRequirement()
@@ -216,6 +215,7 @@ struct PromptToCodePanelToolbar: View {
216215
}
217216
.buttonStyle(.plain)
218217
.disabled(provider.isResponding)
218+
.keyboardShortcut(KeyEquivalent.return, modifiers: [])
219219
}
220220
.frame(maxWidth: .infinity)
221221
.background {
@@ -226,6 +226,14 @@ struct PromptToCodePanelToolbar: View {
226226
RoundedRectangle(cornerRadius: 6)
227227
.stroke(Color(nsColor: .controlColor), lineWidth: 1)
228228
}
229+
.background {
230+
Button(action: {
231+
provider.requirement += "\n"
232+
}) {
233+
EmptyView()
234+
}
235+
.keyboardShortcut(KeyEquivalent.return, modifiers: [.shift])
236+
}
229237
}
230238
.onAppear {
231239
isInputAreaFocused = true
@@ -277,3 +285,4 @@ struct PromptToCodePanel_Error_Bright_Preview: PreviewProvider {
277285
.frame(width: 450, height: 400)
278286
}
279287
}
288+

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ struct WidgetView: View {
2525
Circle().fill(isHovering ? .white.opacity(0.8) : .white.opacity(0.3))
2626
.onTapGesture {
2727
withAnimation(.easeInOut(duration: 0.2)) {
28-
let isDisplayed = panelViewModel.isPanelDisplayed
29-
|| chatWindowViewModel.isPanelDisplayed
28+
let isDisplayed = {
29+
if panelViewModel.isPanelDisplayed && panelViewModel.content != nil { return true }
30+
if chatWindowViewModel.isPanelDisplayed && chatWindowViewModel.chat != nil { return true }
31+
return false
32+
}()
3033
panelViewModel.isPanelDisplayed = !isDisplayed
3134
chatWindowViewModel.isPanelDisplayed = !isDisplayed
3235
}
@@ -75,6 +78,7 @@ struct WidgetView: View {
7578
}
7679
.onChange(of: viewModel.isProcessing) { _ in refreshRing() }
7780
.onChange(of: panelViewModel.content?.contentHash) { _ in refreshRing() }
81+
.onChange(of: chatWindowViewModel.chat?.id) { _ in refreshRing() }
7882
.onHover { yes in
7983
withAnimation(.easeInOut(duration: 0.2)) {
8084
isHovering = yes

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ Whenever you stop typing for a few milliseconds, the app will automatically fetc
144144
- Real-time Suggestions: Call only by Copilot for Xcode. When suggestions are successfully fetched, Copilot for Xcode will run this command to present the suggestions.
145145
- Prefetch Suggestions: Call only by Copilot for Xcode. In the background, Copilot for Xcode will occasionally run this command to prefetch real-time suggestions.
146146

147+
#### Keyboard Shortcuts
148+
149+
| Shortcut | Description |
150+
|:---:|---|
151+
| `⌘W` | Cancel. |
152+
| `⌘↩︎` | Accept suggestion. |
153+
| `⇧↩︎` | Add new line. |
154+
147155
### Chat
148156

149157
This feature is powered by ChatGPT. Please ensure that you have set up your OpenAI account before using it.
@@ -157,7 +165,13 @@ You can detach the chat panel by simply dragging it away. Once detached, the cha
157165
- Chat with Selection: Open a chat window, if there is a selection, the selected code will be added to the prompt.
158166
- Explain Selection: Open a chat window and explain the selected code.
159167

160-
Chat commands are not available in comment mode.
168+
#### Keyboard Shortcuts
169+
170+
| Shortcut | Description |
171+
|:---:|---|
172+
| `⌘W` | Close the chat. |
173+
| `⌘M` | Minimize the chat, you can bring it back with any chat commands or by clicking the circular widget. |
174+
| `⇧↩︎` | Add new line. |
161175

162176
#### Chat Plugins
163177

0 commit comments

Comments
 (0)