Preserve transcript history in Clipboard.

This commit is contained in:
Beingpax 2025-08-11 09:54:52 +05:45
parent 0b8eb71048
commit c06e74ec89
2 changed files with 27 additions and 11 deletions

View File

@ -5,15 +5,19 @@ class CursorPaster {
static func pasteAtCursor(_ text: String) {
let pasteboard = NSPasteboard.general
let preserveTranscript = UserDefaults.standard.bool(forKey: "preserveTranscriptInClipboard")
var savedContents: [(NSPasteboard.PasteboardType, Data)] = []
let currentItems = pasteboard.pasteboardItems ?? []
for item in currentItems {
for type in item.types {
if let data = item.data(forType: type) {
savedContents.append((type, data))
// Only save clipboard contents if we plan to restore them
if !preserveTranscript {
let currentItems = pasteboard.pasteboardItems ?? []
for item in currentItems {
for type in item.types {
if let data = item.data(forType: type) {
savedContents.append((type, data))
}
}
}
}
@ -27,11 +31,14 @@ class CursorPaster {
pasteUsingCommandV()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
if !savedContents.isEmpty {
pasteboard.clearContents()
for (type, data) in savedContents {
pasteboard.setData(data, forType: type)
// Only restore clipboard if preserve setting is disabled
if !preserveTranscript {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
if !savedContents.isEmpty {
pasteboard.clearContents()
for (type, data) in savedContents {
pasteboard.setData(data, forType: type)
}
}
}
}

View File

@ -137,6 +137,15 @@ struct SettingsView: View {
.toggleStyle(.switch)
.help("Automatically mute system audio when recording starts and restore when recording stops")
Toggle(isOn: Binding(
get: { UserDefaults.standard.bool(forKey: "preserveTranscriptInClipboard") },
set: { UserDefaults.standard.set($0, forKey: "preserveTranscriptInClipboard") }
)) {
Text("Preserve transcript in clipboard")
}
.toggleStyle(.switch)
.help("Keep the transcribed text in clipboard instead of restoring the original clipboard content")
}
}