Skip to content

Commit a08e1bc

Browse files
committed
Tweak modification panel behavior
1 parent 297076d commit a08e1bc

File tree

5 files changed

+73
-39
lines changed

5 files changed

+73
-39
lines changed

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCodeGroup.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public struct PromptToCodeGroup {
5050
switch action {
5151
case let .activateOrCreatePromptToCode(s):
5252
if let promptToCode = state.activePromptToCode, s.id == promptToCode.id {
53+
state.selectedTabId = promptToCode.id
5354
return .run { send in
5455
await send(.promptToCode(.element(
5556
id: promptToCode.id,
@@ -61,10 +62,11 @@ public struct PromptToCodeGroup {
6162
await send(.createPromptToCode(s, sendImmediately: false))
6263
}
6364
case let .createPromptToCode(newPromptToCode, sendImmediately):
64-
// insert at 0 so it has high priority then the other detached prompt to codes
65+
var newPromptToCode = newPromptToCode
66+
newPromptToCode.isActiveDocument = newPromptToCode.id == state.activeDocumentURL
6567
state.promptToCodes.append(newPromptToCode)
6668
state.selectedTabId = newPromptToCode.id
67-
return .run { send in
69+
return .run { [newPromptToCode] send in
6870
if sendImmediately,
6971
!newPromptToCode.contextInputController.instruction.string.isEmpty
7072
{
@@ -91,6 +93,10 @@ public struct PromptToCodeGroup {
9193

9294
case let .updateActivePromptToCode(documentURL):
9395
state.activeDocumentURL = documentURL
96+
for index in state.promptToCodes.indices {
97+
state.promptToCodes[index].isActiveDocument =
98+
state.promptToCodes[index].id == documentURL
99+
}
94100
return .none
95101

96102
case let .discardExpiredPromptToCode(documentURLs):

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCodePanel.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public struct PromptToCodePanel {
3737
public var generateDescriptionRequirement: Bool
3838

3939
public var hasEnded = false
40+
41+
public var isActiveDocument: Bool = false
4042

4143
public var snippetPanels: IdentifiedArrayOf<PromptToCodeSnippetPanel.State> {
4244
get {
@@ -85,6 +87,7 @@ public struct PromptToCodePanel {
8587
case cancelButtonTapped
8688
case acceptButtonTapped
8789
case acceptAndContinueButtonTapped
90+
case revealFileButtonClicked
8891
case statusUpdated([String])
8992
case snippetPanel(IdentifiedActionOf<PromptToCodeSnippetPanel>)
9093
}
@@ -248,13 +251,7 @@ public struct PromptToCodePanel {
248251

249252
case .acceptButtonTapped:
250253
state.hasEnded = true
251-
let url = state.promptToCodeState.source.documentURL
252-
let startLine = state.snippetPanels.first?.snippet.attachedRange.start.line ?? 0
253254
return .run { _ in
254-
let activeDocumentURL = await XcodeInspector.shared.safe.activeDocumentURL
255-
if activeDocumentURL != url {
256-
await commandHandler.presentFile(at: url, line: startLine)
257-
}
258255
await commandHandler.acceptModification()
259256
activatePreviousActiveXcode()
260257
}
@@ -265,6 +262,13 @@ public struct PromptToCodePanel {
265262
activateThisApp()
266263
}
267264

265+
case .revealFileButtonClicked:
266+
let url = state.promptToCodeState.source.documentURL
267+
let startLine = state.snippetPanels.first?.snippet.attachedRange.start.line ?? 0
268+
return .run { _ in
269+
await commandHandler.presentFile(at: url, line: startLine)
270+
}
271+
268272
case let .statusUpdated(status):
269273
state.promptToCodeState.status = status
270274
return .none

Core/Sources/SuggestionWidget/PromptToCodePanelGroupView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ struct PromptToCodeTabBarButton: View {
106106
.controlSize(.small)
107107
}
108108
Text(info.tabTitle)
109+
.truncationMode(.middle)
110+
.allowsTightening(true)
109111
}
110112
.font(.callout)
111113
.lineLimit(1)

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanelView.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,12 @@ extension PromptToCodePanelView {
288288
.buttonStyle(CommandButtonStyle(color: .gray))
289289
.keyboardShortcut("w", modifiers: [.command])
290290

291-
if !isCodeEmpty {
292-
AcceptButton(store: store)
291+
if store.isActiveDocument {
292+
if !isCodeEmpty {
293+
AcceptButton(store: store)
294+
}
295+
} else {
296+
RevealButton(store: store)
293297
}
294298
}
295299
.fixedSize()
@@ -357,6 +361,22 @@ extension PromptToCodePanelView {
357361
}
358362
}
359363
}
364+
365+
struct RevealButton: View {
366+
let store: StoreOf<PromptToCodePanel>
367+
368+
var body: some View {
369+
WithPerceptionTracking {
370+
Button(action: {
371+
store.send(.revealFileButtonClicked)
372+
}) {
373+
Text("Jump to File(⌘ + ⏎)")
374+
}
375+
.buttonStyle(CommandButtonStyle(color: .accentColor))
376+
.keyboardShortcut(KeyEquivalent.return, modifiers: [.command])
377+
}
378+
}
379+
}
360380

361381
struct AcceptButton: View {
362382
let store: StoreOf<PromptToCodePanel>

Core/Sources/SuggestionWidget/WidgetWindowsController.swift

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ actor WidgetWindowsController: NSObject {
9797
}
9898
}
9999
}
100-
100+
101101
Task { @MainActor in
102102
windows.chatPanelWindow.isPanelDisplayed = false
103103
}
@@ -132,36 +132,38 @@ private extension WidgetWindowsController {
132132
observeToAppTask = Task {
133133
await windows.orderFront()
134134
135-
for await notification in await notifications.notifications() {
136-
try Task.checkCancellation()
137-
138-
/// Hide the widgets before switching to another window/editor
139-
/// so the transition looks better.
140-
func hideWidgetForTransitions() async {
141-
let newDocumentURL = await xcodeInspector.safe.realtimeActiveDocumentURL
142-
let documentURL = await MainActor
143-
.run { store.withState { $0.focusingDocumentURL } }
144-
if documentURL != newDocumentURL {
145-
await send(.panel(.removeDisplayedContent))
146-
await hidePanelWindows()
147-
}
148-
await send(.updateFocusingDocumentURL)
149-
}
150-
151-
func removeContent() async {
135+
/// Hide the widgets before switching to another window/editor
136+
/// so the transition looks better.
137+
func hideWidgetForTransitions() async {
138+
let newDocumentURL = await xcodeInspector.safe.realtimeActiveDocumentURL
139+
let documentURL = await MainActor
140+
.run { store.withState { $0.focusingDocumentURL } }
141+
if documentURL != newDocumentURL {
152142
await send(.panel(.removeDisplayedContent))
143+
await hidePanelWindows()
153144
}
145+
await send(.updateFocusingDocumentURL)
146+
}
154147
155-
func updateWidgetsAndNotifyChangeOfEditor(immediately: Bool) async {
156-
await send(.panel(.switchToAnotherEditorAndUpdateContent))
157-
updateWindowLocation(animated: false, immediately: immediately)
158-
updateWindowOpacity(immediately: immediately)
159-
}
148+
func removeContent() async {
149+
await send(.panel(.removeDisplayedContent))
150+
}
160151
161-
func updateWidgets(immediately: Bool) async {
162-
updateWindowLocation(animated: false, immediately: immediately)
163-
updateWindowOpacity(immediately: immediately)
164-
}
152+
func updateWidgetsAndNotifyChangeOfEditor(immediately: Bool) async {
153+
await send(.panel(.switchToAnotherEditorAndUpdateContent))
154+
updateWindowLocation(animated: false, immediately: immediately)
155+
updateWindowOpacity(immediately: immediately)
156+
}
157+
158+
func updateWidgets(immediately: Bool) async {
159+
updateWindowLocation(animated: false, immediately: immediately)
160+
updateWindowOpacity(immediately: immediately)
161+
}
162+
163+
await updateWidgetsAndNotifyChangeOfEditor(immediately: true)
164+
165+
for await notification in await notifications.notifications() {
166+
try Task.checkCancellation()
165167
166168
switch notification.kind {
167169
case .focusedWindowChanged:
@@ -257,7 +259,7 @@ private extension WidgetWindowsController {
257259
extension WidgetWindowsController {
258260
@MainActor
259261
func hidePanelWindows() {
260-
windows.sharedPanelWindow.alphaValue = 0
262+
// windows.sharedPanelWindow.alphaValue = 0
261263
windows.suggestionPanelWindow.alphaValue = 0
262264
}
263265
@@ -903,7 +905,7 @@ class WidgetWindow: CanBecomeKeyWindow {
903905
: .normal
904906

905907
if targetLevel != level {
906-
self.orderFrontRegardless()
908+
orderFrontRegardless()
907909
level = targetLevel
908910
}
909911
}

0 commit comments

Comments
 (0)