Skip to content

Commit 6e6bc96

Browse files
committed
Add a dismiss button to non-compact mode suggestion
1 parent ae6c551 commit 6e6bc96

File tree

1 file changed

+86
-132
lines changed

1 file changed

+86
-132
lines changed

Core/Sources/SuggestionWidget/SuggestionPanelContent/CodeBlockSuggestionPanel.swift

Lines changed: 86 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ struct CodeBlockSuggestionPanel: View {
3131

3232
Spacer()
3333

34+
Button(action: {
35+
suggestion.dismissSuggestion()
36+
}) {
37+
Text("Dismiss").foregroundStyle(.tertiary).padding(.trailing, 4)
38+
}.buttonStyle(.plain)
39+
3440
Button(action: {
3541
suggestion.rejectSuggestion()
3642
}) {
@@ -41,7 +47,7 @@ struct CodeBlockSuggestionPanel: View {
4147
suggestion.acceptSuggestion()
4248
}) {
4349
Text("Accept")
44-
}.buttonStyle(CommandButtonStyle(color: .indigo))
50+
}.buttonStyle(CommandButtonStyle(color: .accentColor))
4551
}
4652
.padding()
4753
.foregroundColor(.secondary)
@@ -72,7 +78,7 @@ struct CodeBlockSuggestionPanel: View {
7278
}.buttonStyle(.plain)
7379

7480
Spacer()
75-
81+
7682
Button(action: {
7783
suggestion.dismissSuggestion()
7884
}) {
@@ -112,146 +118,94 @@ struct CodeBlockSuggestionPanel: View {
112118

113119
// MARK: - Previews
114120

115-
struct CodeBlockSuggestionPanel_Dark_Preview: PreviewProvider {
116-
static var previews: some View {
117-
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
118-
code: """
119-
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
120-
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
121-
Text(viewModel.suggestion[index])
122-
.frame(maxWidth: .infinity, alignment: .leading)
123-
.multilineTextAlignment(.leading)
124-
}
125-
""",
126-
language: "swift",
127-
startLineIndex: 8,
128-
suggestionCount: 2,
129-
currentSuggestionIndex: 0
130-
))
131-
.preferredColorScheme(.dark)
132-
.frame(width: 450, height: 400)
133-
.background {
134-
HStack {
135-
Color.red
136-
Color.green
137-
Color.blue
138-
}
121+
#Preview("Code Block Suggestion Panel") {
122+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
123+
code: """
124+
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
125+
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
126+
Text(viewModel.suggestion[index])
127+
.frame(maxWidth: .infinity, alignment: .leading)
128+
.multilineTextAlignment(.leading)
139129
}
140-
}
141-
}
142-
143-
struct CodeBlockSuggestionPanel_Bright_Preview: PreviewProvider {
144-
static var previews: some View {
145-
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
146-
code: """
147-
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
148-
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
149-
Text(viewModel.suggestion[index])
150-
.frame(maxWidth: .infinity, alignment: .leading)
151-
.multilineTextAlignment(.leading)
152-
}
153-
""",
154-
language: "swift",
155-
startLineIndex: 8,
156-
suggestionCount: 2,
157-
currentSuggestionIndex: 0
158-
))
159-
.preferredColorScheme(.light)
160-
.frame(width: 450, height: 400)
161-
.background {
162-
HStack {
163-
Color.red
164-
Color.green
165-
Color.blue
166-
}
130+
""",
131+
language: "swift",
132+
startLineIndex: 8,
133+
suggestionCount: 2,
134+
currentSuggestionIndex: 0
135+
), suggestionDisplayCompactMode: .init(
136+
wrappedValue: false,
137+
"suggestionDisplayCompactMode",
138+
store: {
139+
let userDefault =
140+
UserDefaults(suiteName: "CodeBlockSuggestionPanel_CompactToolBar_Preview")
141+
userDefault?.set(false, for: \.suggestionDisplayCompactMode)
142+
return userDefault!
143+
}()
144+
))
145+
.frame(width: 450, height: 400)
146+
.background {
147+
HStack {
148+
Color.red
149+
Color.green
150+
Color.blue
167151
}
168152
}
169153
}
170154

171-
struct CodeBlockSuggestionPanel_CompactToolBar_Preview: PreviewProvider {
172-
static let userDefault = {
173-
let userDefault = UserDefaults(suiteName: "CodeBlockSuggestionPanel_CompactToolBar_Preview")
174-
userDefault?.set(true, for: \.suggestionDisplayCompactMode)
175-
return userDefault!
176-
}()
177-
178-
static var previews: some View {
179-
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
180-
code: """
181-
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
182-
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
183-
Text(viewModel.suggestion[index])
184-
.frame(maxWidth: .infinity, alignment: .leading)
185-
.multilineTextAlignment(.leading)
186-
}
187-
""",
188-
language: "swift",
189-
startLineIndex: 8,
190-
suggestionCount: 2,
191-
currentSuggestionIndex: 0
192-
), suggestionDisplayCompactMode: .init(
193-
wrappedValue: true,
194-
"suggestionDisplayCompactMode",
195-
store: Self.userDefault
196-
))
197-
.preferredColorScheme(.light)
198-
.frame(width: 450, height: 400)
199-
.background {
200-
HStack {
201-
Color.red
202-
Color.green
203-
Color.blue
204-
}
155+
#Preview("Code Block Suggestion Panel Compact Mode") {
156+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
157+
code: """
158+
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
159+
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
160+
Text(viewModel.suggestion[index])
161+
.frame(maxWidth: .infinity, alignment: .leading)
162+
.multilineTextAlignment(.leading)
205163
}
206-
}
207-
}
208-
209-
struct CodeBlockSuggestionPanel_Dark_Objc_Preview: PreviewProvider {
210-
static var previews: some View {
211-
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
212-
code: """
213-
- (void)addSubview:(UIView *)view {
214-
[self addSubview:view];
215-
}
216-
""",
217-
language: "objective-c",
218-
startLineIndex: 8,
219-
suggestionCount: 2,
220-
currentSuggestionIndex: 0
221-
))
222-
.preferredColorScheme(.dark)
223-
.frame(width: 450, height: 400)
224-
.background {
225-
HStack {
226-
Color.red
227-
Color.green
228-
Color.blue
229-
}
164+
""",
165+
language: "swift",
166+
startLineIndex: 8,
167+
suggestionCount: 2,
168+
currentSuggestionIndex: 0
169+
), suggestionDisplayCompactMode: .init(
170+
wrappedValue: true,
171+
"suggestionDisplayCompactMode",
172+
store: {
173+
let userDefault =
174+
UserDefaults(suiteName: "CodeBlockSuggestionPanel_CompactToolBar_Preview")
175+
userDefault?.set(true, for: \.suggestionDisplayCompactMode)
176+
return userDefault!
177+
}()
178+
))
179+
.preferredColorScheme(.light)
180+
.frame(width: 450, height: 400)
181+
.background {
182+
HStack {
183+
Color.red
184+
Color.green
185+
Color.blue
230186
}
231187
}
232188
}
233189

234-
struct CodeBlockSuggestionPanel_Bright_Objc_Preview: PreviewProvider {
235-
static var previews: some View {
236-
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
237-
code: """
238-
- (void)addSubview:(UIView *)view {
239-
[self addSubview:view];
240-
}
241-
""",
242-
language: "objective-c",
243-
startLineIndex: 8,
244-
suggestionCount: 2,
245-
currentSuggestionIndex: 0
246-
))
247-
.preferredColorScheme(.light)
248-
.frame(width: 450, height: 400)
249-
.background {
250-
HStack {
251-
Color.red
252-
Color.green
253-
Color.blue
254-
}
190+
#Preview("Code Block Suggestion Panel Highlight ObjC") {
191+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
192+
code: """
193+
- (void)addSubview:(UIView *)view {
194+
[self addSubview:view];
195+
}
196+
""",
197+
language: "objective-c",
198+
startLineIndex: 8,
199+
suggestionCount: 2,
200+
currentSuggestionIndex: 0
201+
))
202+
.preferredColorScheme(.light)
203+
.frame(width: 450, height: 400)
204+
.background {
205+
HStack {
206+
Color.red
207+
Color.green
208+
Color.blue
255209
}
256210
}
257211
}

0 commit comments

Comments
 (0)