From e68951f806c84714d71566cfe657960c53cf1213 Mon Sep 17 00:00:00 2001 From: German Date: Mon, 1 Jul 2024 18:15:44 +0200 Subject: [PATCH] feat: copy text with eager decoding, keyboard shortcut (#178) --- .../WhisperAX/Views/ContentView.swift | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Examples/WhisperAX/WhisperAX/Views/ContentView.swift b/Examples/WhisperAX/WhisperAX/Views/ContentView.swift index bada3cac..61c14969 100644 --- a/Examples/WhisperAX/WhisperAX/Views/ContentView.swift +++ b/Examples/WhisperAX/WhisperAX/Views/ContentView.swift @@ -202,16 +202,26 @@ struct ContentView: View { .toolbar(content: { ToolbarItem { Button { - let fullTranscript = formatSegments(confirmedSegments + unconfirmedSegments, withTimestamps: enableTimestamps).joined(separator: "\n") - #if os(iOS) - UIPasteboard.general.string = fullTranscript - #elseif os(macOS) - NSPasteboard.general.clearContents() - NSPasteboard.general.setString(fullTranscript, forType: .string) - #endif + if (!enableEagerDecoding) { + let fullTranscript = formatSegments(confirmedSegments + unconfirmedSegments, withTimestamps: enableTimestamps).joined(separator: "\n") + #if os(iOS) + UIPasteboard.general.string = fullTranscript + #elseif os(macOS) + NSPasteboard.general.clearContents() + NSPasteboard.general.setString(fullTranscript, forType: .string) + #endif + } else { + #if os(iOS) + UIPasteboard.general.string = confirmedText + hypothesisText + #elseif os(macOS) + NSPasteboard.general.clearContents() + NSPasteboard.general.setString(confirmedText + hypothesisText, forType: .string) + #endif + } } label: { Label("Copy Text", systemImage: "doc.on.doc") } + .keyboardShortcut("c", modifiers: .command) .foregroundColor(.primary) .frame(minWidth: 0, maxWidth: .infinity) }