Skip to content

Commit 6a690f7

Browse files
committed
Adjust prompt to code panel
1 parent 2815292 commit 6a690f7

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCode.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public struct PromptToCode: ReducerProtocol {
6363
@BindingState public var prompt: String
6464
@BindingState public var isContinuous: Bool
6565
@BindingState public var isAttachedToSelectionRange: Bool
66-
66+
67+
public var filename: String { documentURL.lastPathComponent }
6768
public var canRevert: Bool { history != .empty }
6869

6970
public init(

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension PromptToCodePanel {
3131
let store: StoreOf<PromptToCode>
3232

3333
struct AttachButtonState: Equatable {
34+
var attachedToFilename: String
3435
var isAttachedToSelectionRange: Bool
3536
var selectionRange: CursorRange?
3637
}
@@ -45,6 +46,7 @@ extension PromptToCodePanel {
4546
WithViewStore(
4647
store,
4748
observe: { AttachButtonState(
49+
attachedToFilename: $0.filename,
4850
isAttachedToSelectionRange: $0.isAttachedToSelectionRange,
4951
selectionRange: $0.selectionRange
5052
) }
@@ -53,7 +55,7 @@ extension PromptToCodePanel {
5355
let color: Color = isAttached ? .indigo : .secondary.opacity(0.6)
5456
HStack(spacing: 4) {
5557
Image(
56-
systemName: isAttached ? "bandage" : "character.cursor.ibeam"
58+
systemName: isAttached ? "link" : "character.cursor.ibeam"
5759
)
5860
.resizable()
5961
.aspectRatio(contentMode: .fit)
@@ -68,13 +70,16 @@ extension PromptToCodePanel {
6870
)
6971
)
7072

71-
let text: String = {
72-
if isAttached, let range = viewStore.state.selectionRange {
73-
return range.description
74-
}
75-
return "text cursor"
76-
}()
77-
Text(text).foregroundColor(.primary)
73+
if isAttached {
74+
HStack(spacing: 4) {
75+
Text(viewStore.state.attachedToFilename)
76+
if let range = viewStore.state.selectionRange {
77+
Text(range.description)
78+
}
79+
}.foregroundColor(.primary)
80+
} else {
81+
Text("text selection").foregroundColor(.secondary)
82+
}
7883
}
7984
.padding(2)
8085
.padding(.trailing, 4)
@@ -422,8 +427,8 @@ struct PromptToCodePanel_Preview: PreviewProvider {
422427
language: .builtIn(.swift),
423428
indentSize: 4,
424429
usesTabsForIndentation: false,
425-
projectRootURL: URL(fileURLWithPath: ""),
426-
documentURL: URL(fileURLWithPath: ""),
430+
projectRootURL: URL(fileURLWithPath: "path/to/file.txt"),
431+
documentURL: URL(fileURLWithPath: "path/to/file.txt"),
427432
allCode: "",
428433
commandName: "Generate Code",
429434
description: "Hello world",
@@ -452,8 +457,8 @@ struct PromptToCodePanel_Error_Detached_Preview: PreviewProvider {
452457
language: .builtIn(.swift),
453458
indentSize: 4,
454459
usesTabsForIndentation: false,
455-
projectRootURL: URL(fileURLWithPath: ""),
456-
documentURL: URL(fileURLWithPath: ""),
460+
projectRootURL: URL(fileURLWithPath: "path/to/file.txt"),
461+
documentURL: URL(fileURLWithPath: "path/to/file.txt"),
457462
allCode: "",
458463
commandName: "Generate Code",
459464
description: "Hello world",

0 commit comments

Comments
 (0)