Preserve transcript history in Clipboard.
This commit is contained in:
parent
0b8eb71048
commit
c06e74ec89
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user