Skip to content

Commit e9a1f72

Browse files
committed
Add top bar to prompt to code panel
1 parent 2c7664c commit e9a1f72

File tree

4 files changed

+290
-218
lines changed

4 files changed

+290
-218
lines changed

Core/Sources/Service/GUI/PromptToCodeProvider+Service.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ extension PromptToCodeProvider {
1313
code: service.code,
1414
language: service.language.rawValue,
1515
description: "",
16-
startLineIndex: service.selectionRange.start.line,
17-
startLineColumn: service.selectionRange.start.character,
16+
attachedToRange: service.selectionRange,
1817
name: name
1918
)
2019

Core/Sources/SuggestionWidget/Providers/PromptToCodeProvider.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import Foundation
2+
import SuggestionModel
23
import SwiftUI
34

45
public final class PromptToCodeProvider: ObservableObject {
56
let id = UUID()
67
let name: String?
7-
8+
89
@Published public var code: String
910
@Published public var language: String
1011
@Published public var description: String
1112
@Published public var isResponding: Bool
12-
@Published public var startLineIndex: Int
13-
@Published public var startLineColumn: Int
13+
public var startLineIndex: Int { attachedToRange?.start.line ?? 0 }
14+
public var startLineColumn: Int { attachedToRange?.start.character ?? 0 }
15+
@Published public var attachedToRange: CursorRange?
1416
@Published public var requirement: String
1517
@Published public var errorMessage: String
1618
@Published public var canRevert: Bool
@@ -28,8 +30,7 @@ public final class PromptToCodeProvider: ObservableObject {
2830
language: String = "",
2931
description: String = "",
3032
isResponding: Bool = false,
31-
startLineIndex: Int = 0,
32-
startLineColumn: Int = 0,
33+
attachedToRange: CursorRange? = nil,
3334
requirement: String = "",
3435
errorMessage: String = "",
3536
canRevert: Bool = false,
@@ -46,8 +47,7 @@ public final class PromptToCodeProvider: ObservableObject {
4647
self.language = language
4748
self.description = description
4849
self.isResponding = isResponding
49-
self.startLineIndex = startLineIndex
50-
self.startLineColumn = startLineColumn
50+
self.attachedToRange = attachedToRange
5151
self.requirement = requirement
5252
self.errorMessage = errorMessage
5353
self.canRevert = canRevert
@@ -65,11 +65,14 @@ public final class PromptToCodeProvider: ObservableObject {
6565
onRevertTapped()
6666
errorMessage = ""
6767
}
68+
6869
func stopResponding() {
6970
onStopRespondingTap()
7071
errorMessage = ""
7172
}
73+
7274
func cancel() { onCancelTapped() }
75+
7376
func sendRequirement() {
7477
guard !isResponding else { return }
7578
guard !requirement.isEmpty else { return }
@@ -79,6 +82,7 @@ public final class PromptToCodeProvider: ObservableObject {
7982
}
8083

8184
func acceptSuggestion() { onAcceptSuggestionTapped() }
82-
85+
8386
func toggleContinuous() { onContinuousToggleClick() }
8487
}
88+

Core/Sources/SuggestionWidget/SharedPanelView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,21 @@ struct SharedPanelView: View {
9797
}
9898

9999
struct CommandButtonStyle: ButtonStyle {
100-
let color: Color
100+
var color: Color
101+
var cornerRadius: Double = 4
101102

102103
func makeBody(configuration: Configuration) -> some View {
103104
configuration.label
104105
.padding(.vertical, 4)
105106
.padding(.horizontal, 8)
106107
.foregroundColor(.white)
107108
.background(
108-
RoundedRectangle(cornerRadius: 4, style: .continuous)
109+
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
109110
.fill(color.opacity(configuration.isPressed ? 0.8 : 1))
110111
.animation(.easeOut(duration: 0.1), value: configuration.isPressed)
111112
)
112113
.overlay {
113-
RoundedRectangle(cornerRadius: 4, style: .continuous)
114+
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
114115
.stroke(Color.white.opacity(0.2), style: .init(lineWidth: 1))
115116
}
116117
}

0 commit comments

Comments
 (0)