import SharedUIComponents import SwiftUI struct CodeBlockSuggestionPanel: View { @ObservedObject var suggestion: SuggestionProvider @Environment(\.colorScheme) var colorScheme @AppStorage(\.suggestionCodeFontSize) var fontSize struct ToolBar: View { @ObservedObject var suggestion: SuggestionProvider var body: some View { HStack { Button(action: { suggestion.selectPreviousSuggestion() }) { Image(systemName: "chevron.left") }.buttonStyle(.plain) Text( "\(suggestion.currentSuggestionIndex + 1) / \(suggestion.suggestionCount)" ) .monospacedDigit() Button(action: { suggestion.selectNextSuggestion() }) { Image(systemName: "chevron.right") }.buttonStyle(.plain) Spacer() Button(action: { suggestion.rejectSuggestion() }) { Text("Reject") }.buttonStyle(CommandButtonStyle(color: .gray)) Button(action: { suggestion.acceptSuggestion() }) { Text("Accept") }.buttonStyle(CommandButtonStyle(color: .indigo)) } .padding() .foregroundColor(.secondary) .background(.regularMaterial) } } var body: some View { VStack(spacing: 0) { CustomScrollView { CodeBlock( code: suggestion.code, language: suggestion.language, startLineIndex: suggestion.startLineIndex, colorScheme: colorScheme, fontSize: fontSize ) .frame(maxWidth: .infinity) } .background(Color.contentBackground) ToolBar(suggestion: suggestion) } .xcodeStyleFrame() } } // MARK: - Previews struct CodeBlockSuggestionPanel_Dark_Preview: PreviewProvider { static var previews: some View { CodeBlockSuggestionPanel(suggestion: SuggestionProvider( code: """ LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) { ForEach(0..