Skip to content

Commit ae454a1

Browse files
committed
Merge branch 'feature/compact-suggestion' into develop
2 parents e1360a2 + 63737ca commit ae454a1

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

Core/Sources/HostApp/FeatureSettings/SuggestionSettingsView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct SuggestionSettingsView: View {
1919
var suggestionCodeFontSize
2020
@AppStorage(\.suggestionFeatureProvider)
2121
var suggestionFeatureProvider
22+
@AppStorage(\.suggestionDisplayCompactMode)
23+
var suggestionDisplayCompactMode
2224
init() {}
2325
}
2426

@@ -105,6 +107,10 @@ struct SuggestionSettingsView: View {
105107
}
106108

107109
Group {
110+
Toggle(isOn: $settings.suggestionDisplayCompactMode) {
111+
Text("Hide Buttons")
112+
}
113+
108114
Toggle(isOn: $settings.hideCommonPrecedingSpacesInSuggestion) {
109115
Text("Hide Common Preceding Spaces")
110116
}

Core/Sources/SuggestionWidget/SuggestionPanelContent/CodeBlockSuggestionPanel.swift

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct CodeBlockSuggestionPanel: View {
55
@ObservedObject var suggestion: SuggestionProvider
66
@Environment(\.colorScheme) var colorScheme
77
@AppStorage(\.suggestionCodeFontSize) var fontSize
8+
@AppStorage(\.suggestionDisplayCompactMode) var suggestionDisplayCompactMode
89

910
struct ToolBar: View {
1011
@ObservedObject var suggestion: SuggestionProvider
@@ -48,6 +49,37 @@ struct CodeBlockSuggestionPanel: View {
4849
}
4950
}
5051

52+
struct CompactToolBar: View {
53+
@ObservedObject var suggestion: SuggestionProvider
54+
55+
var body: some View {
56+
HStack {
57+
Button(action: {
58+
suggestion.selectPreviousSuggestion()
59+
}) {
60+
Image(systemName: "chevron.left")
61+
}.buttonStyle(.plain)
62+
63+
Text(
64+
"\(suggestion.currentSuggestionIndex + 1) / \(suggestion.suggestionCount)"
65+
)
66+
.monospacedDigit()
67+
68+
Button(action: {
69+
suggestion.selectNextSuggestion()
70+
}) {
71+
Image(systemName: "chevron.right")
72+
}.buttonStyle(.plain)
73+
74+
Spacer()
75+
}
76+
.padding(4)
77+
.font(.caption)
78+
.foregroundColor(.secondary)
79+
.background(.regularMaterial)
80+
}
81+
}
82+
5183
var body: some View {
5284
VStack(spacing: 0) {
5385
CustomScrollView {
@@ -62,7 +94,11 @@ struct CodeBlockSuggestionPanel: View {
6294
}
6395
.background(Color.contentBackground)
6496

65-
ToolBar(suggestion: suggestion)
97+
if suggestionDisplayCompactMode {
98+
CompactToolBar(suggestion: suggestion)
99+
} else {
100+
ToolBar(suggestion: suggestion)
101+
}
66102
}
67103
.xcodeStyleFrame()
68104
}
@@ -126,6 +162,44 @@ struct CodeBlockSuggestionPanel_Bright_Preview: PreviewProvider {
126162
}
127163
}
128164

165+
struct CodeBlockSuggestionPanel_CompactToolBar_Preview: PreviewProvider {
166+
static let userDefault = {
167+
let userDefault = UserDefaults(suiteName: "CodeBlockSuggestionPanel_CompactToolBar_Preview")
168+
userDefault?.set(true, for: \.suggestionDisplayCompactMode)
169+
return userDefault!
170+
}()
171+
172+
static var previews: some View {
173+
CodeBlockSuggestionPanel(suggestion: SuggestionProvider(
174+
code: """
175+
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
176+
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
177+
Text(viewModel.suggestion[index])
178+
.frame(maxWidth: .infinity, alignment: .leading)
179+
.multilineTextAlignment(.leading)
180+
}
181+
""",
182+
language: "swift",
183+
startLineIndex: 8,
184+
suggestionCount: 2,
185+
currentSuggestionIndex: 0
186+
), suggestionDisplayCompactMode: .init(
187+
wrappedValue: true,
188+
"suggestionDisplayCompactMode",
189+
store: Self.userDefault
190+
))
191+
.preferredColorScheme(.light)
192+
.frame(width: 450, height: 400)
193+
.background {
194+
HStack {
195+
Color.red
196+
Color.green
197+
Color.blue
198+
}
199+
}
200+
}
201+
}
202+
129203
struct CodeBlockSuggestionPanel_Dark_Objc_Preview: PreviewProvider {
130204
static var previews: some View {
131205
CodeBlockSuggestionPanel(suggestion: SuggestionProvider(

Tool/Sources/Preferences/Keys.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ public extension UserDefaultPreferenceKeys {
217217
var realtimeSuggestionToggle: PreferenceKey<Bool> {
218218
.init(defaultValue: true, key: "RealtimeSuggestionToggle")
219219
}
220+
221+
var suggestionDisplayCompactMode: PreferenceKey<Bool> {
222+
.init(defaultValue: false, key: "SuggestionDisplayCompactMode")
223+
}
220224

221225
var suggestionCodeFontSize: PreferenceKey<Double> {
222226
.init(defaultValue: 13, key: "SuggestionCodeFontSize")

0 commit comments

Comments
 (0)