Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Copilot for Xcode/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ final class DebugSettings: ObservableObject {
var preCacheOnFileOpen: Bool
@AppStorage(\.runNodeWithInteractiveLoggedInShell)
var runNodeWithInteractiveLoggedInShell: Bool
@AppStorage(\.useCustomScrollViewWorkaround) var useCustomScrollViewWorkaround
init() {}
}

Expand All @@ -30,6 +31,10 @@ struct DebugSettingsView: View {
Text("Run node with interactive logged-in bash")
}
.toggleStyle(.switch)
Toggle(isOn: $settings.useCustomScrollViewWorkaround) {
Text("Use custom scroll view workaround for smooth scrolling")
}
.toggleStyle(.switch)
}
}.buttonStyle(.copilot)
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let package = Package(
.package(url: "https://github.com/raspu/Highlightr", from: "2.1.0"),
.package(url: "https://github.com/JohnSundell/Splash", branch: "master"),
.package(url: "https://github.com/nmdias/FeedKit", from: "9.1.2"),
.package(url: "https://github.com/intitni/swift-markdown-ui", branch: "main"),
.package(url: "https://github.com/gonzalezreal/swift-markdown-ui", from: "2.1.0"),
.package(url: "https://github.com/sparkle-project/Sparkle", from: "2.0.0"),
],
targets: [
Expand Down
6 changes: 6 additions & 0 deletions Core/Sources/Preferences/Keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public struct UserDefaultPreferenceKeys {
public var preCacheOnFileOpen: FeatureFlags.PreCacheOnFileOpen { .init() }
public var runNodeWithInteractiveLoggedInShell: FeatureFlags
.RunNodeWithInteractiveLoggedInShell { .init() }
public var useCustomScrollViewWorkaround: FeatureFlags.UseCustomScrollViewWorkaround { .init() }
}

public enum FeatureFlags {
Expand All @@ -191,4 +192,9 @@ public enum FeatureFlags {
public let defaultValue = true
public let key = "FeatureFlag-RunNodeWithInteractiveLoggedInShell"
}

public struct UseCustomScrollViewWorkaround: UserDefaultPreferenceKey {
public let defaultValue = true
public let key = "FeatureFlag-UseCustomScrollViewWorkaround"
}
}
34 changes: 34 additions & 0 deletions Core/Sources/SuggestionWidget/CopyButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import AppKit
import SwiftUI

struct CopyButton: View {
var copy: () -> Void
@State var isCopied = false
var body: some View {
Button(action: {
withAnimation(.linear(duration: 0.1)) {
isCopied = true
}
copy()
Task {
try await Task.sleep(nanoseconds: 1_000_000_000)
withAnimation(.linear(duration: 0.1)) {
isCopied = false
}
}
}) {
Image(systemName: isCopied ? "checkmark.circle" : "doc.on.doc")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 14, height: 14)
.frame(width: 20, height: 20, alignment: .center)
.foregroundColor(.secondary)
.background(
.regularMaterial,
in: RoundedRectangle(cornerRadius: 4, style: .circular)
)
.padding(4)
}
.buttonStyle(.borderless)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import AppKit
import SwiftUI
import Combine

/// Used to workaround a SwiftUI bug. https://github.com/intitni/CopilotForXcode/issues/122
struct CustomScrollView<Content: View>: View {
@ViewBuilder var content: () -> Content
@State var height: Double = 100
@AppStorage(\.useCustomScrollViewWorkaround) var useNSScrollViewWrapper

var body: some View {
if useNSScrollViewWrapper {
List {
content()
.listRowInsets(EdgeInsets(top: 0, leading: -8, bottom: 0, trailing: -8))
}
.listStyle(.plain)
.frame(idealHeight: height)
.background {
ComputeHeight(height: $height) {
content()
}
.frame(maxWidth: .infinity)
.opacity(0)
}
} else {
ScrollView {
content()
}
}
}
}

private struct ComputeHeight<Content: View>: NSViewRepresentable {
@Binding var height: Double
@ViewBuilder var content: () -> Content

func makeNSView(context: Context) -> NSView {
let view = NSView()
return view
}

func updateNSView(_ nsView: NSView, context: Context) {
updateHeight(nsView)
}

func updateHeight(_ nsView: NSView) {
let contentView = content()
let hostingView = NSHostingView(
rootView: contentView.frame(width: nsView.frame.width == 0 ? 200 : nsView.frame.width)
)
let size = hostingView.fittingSize

if height != size.height {
Task { @MainActor in
height = size.height
}
}
}
}
27 changes: 27 additions & 0 deletions Core/Sources/SuggestionWidget/Styles.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppKit
import MarkdownUI
import SwiftUI

enum Style {
Expand Down Expand Up @@ -53,3 +54,29 @@ extension View {
)
}
}

extension MarkdownUI.Theme {
static var custom: MarkdownUI.Theme {
.gitHub.text {
BackgroundColor(Color.clear)
}
.codeBlock { configuration in
configuration.label
.relativeLineSpacing(.em(0.225))
.markdownTextStyle {
FontFamilyVariant(.monospaced)
FontSize(.em(0.85))
}
.padding(16)
.background(Color(nsColor: .textBackgroundColor).opacity(0.7))
.clipShape(RoundedRectangle(cornerRadius: 6))
.overlay(alignment: .topTrailing) {
CopyButton {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(configuration.content, forType: .string)
}
}
.markdownMargin(top: 0, bottom: 16)
}
}
}
Loading