Skip to content
Open
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
123 changes: 123 additions & 0 deletions Bifcode.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

105 changes: 105 additions & 0 deletions BifcodePackage/Package.resolved

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

31 changes: 30 additions & 1 deletion BifcodePackage/Sources/BifcodeFeature/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ContentView.swift
//
// Created on 17.12.2025.
// Copyright © 2025 IGR Soft. All rights reserved.
// Copyright © 2026 IGR Soft. All rights reserved.
//

import AppKit
Expand Down Expand Up @@ -128,6 +128,7 @@ public struct ContentView: View {
dontTitleSetting: $dontTitleSetting,
isExportDisabled: isCodeEmpty,
onExport: { Task(operation: exportImage) },
onCopyToClipboard: { Task(operation: copyToClipboard) },
onLanguageChange: { viewModel.setLanguage($0) }
)

Expand Down Expand Up @@ -262,6 +263,34 @@ public struct ContentView: View {
}
}

/// Copies the current code panels as an image to the clipboard.
///
/// This method uses the same rendering pipeline as ``exportImage()``
/// but copies the result to the system clipboard instead of saving to disk.
///
/// > Note: Copy is disabled when both code panels are empty.
@MainActor
private func copyToClipboard() async {
guard let nsImage = await renderExportViewToImage() else {
withAnimation(reduceMotion ? nil : .easeInOut(duration: 0.25)) {
exportResult = .failure(ExportError.conversionFailed)
}
return
}

let pasteboard = NSPasteboard.general
pasteboard.clearContents()
let success = pasteboard.writeObjects([nsImage])

withAnimation(reduceMotion ? nil : .easeInOut(duration: 0.25)) {
if success {
exportResult = .copied
} else {
exportResult = .failure(ExportError.conversionFailed)
}
}
}

/// Renders the export view to an NSImage using an offscreen window.
///
/// This method uses an offscreen `NSWindow` technique because `ImageRenderer`
Expand Down
Loading