From 4361597ee95f8ce3ff91f46108c0af3c4dcb32ce Mon Sep 17 00:00:00 2001 From: Beingpax Date: Sun, 5 Oct 2025 16:53:09 +0545 Subject: [PATCH] Use selected text across all enhancement prompts and not only aiassistant prompt --- VoiceInk/Services/AIEnhancementService.swift | 23 +++++++++++--------- VoiceInk/Services/SelectedTextService.swift | 5 ----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/VoiceInk/Services/AIEnhancementService.swift b/VoiceInk/Services/AIEnhancementService.swift index 01c80f6..3d07523 100644 --- a/VoiceInk/Services/AIEnhancementService.swift +++ b/VoiceInk/Services/AIEnhancementService.swift @@ -140,18 +140,21 @@ class AIEnhancementService: ObservableObject { let clipboardSnapshot = NSPasteboard.general.string(forType: .string) let selectedText = SelectedTextService.fetchSelectedText() - if let activePrompt = activePrompt, - activePrompt.id == PredefinedPrompts.assistantPromptId, - let selectedText = selectedText, !selectedText.isEmpty { + if let selectedText = selectedText, !selectedText.isEmpty { + let generalContextSection = "\n\n\n\(selectedText)\n" - let selectedTextContext = "\n\nSelected Text: \(selectedText)" - let generalContextSection = "\n\n\(selectedTextContext)\n" - let dictionaryContextSection = if !dictionaryContextService.getDictionaryContext().isEmpty { - "\n\n\(dictionaryContextService.getDictionaryContext())\n" + if let activePrompt = activePrompt { + if activePrompt.id == PredefinedPrompts.assistantPromptId { + return activePrompt.promptText + generalContextSection + } else { + return activePrompt.finalPromptText + generalContextSection + } } else { - "" + if let defaultPrompt = allPrompts.first(where: { $0.id == PredefinedPrompts.defaultPromptId }) { + return defaultPrompt.finalPromptText + generalContextSection + } + return AIPrompts.assistantMode + generalContextSection } - return activePrompt.promptText + generalContextSection + dictionaryContextSection } let clipboardContext = if useClipboardContext, @@ -192,7 +195,7 @@ class AIEnhancementService: ObservableObject { if activePrompt.id == PredefinedPrompts.assistantPromptId { return activePrompt.promptText + generalContextSection + dictionaryContextSection } - + var systemMessage = activePrompt.finalPromptText systemMessage += generalContextSection + dictionaryContextSection return systemMessage diff --git a/VoiceInk/Services/SelectedTextService.swift b/VoiceInk/Services/SelectedTextService.swift index 19fd0e6..27d732a 100644 --- a/VoiceInk/Services/SelectedTextService.swift +++ b/VoiceInk/Services/SelectedTextService.swift @@ -5,11 +5,6 @@ class SelectedTextService { private static let privatePasteboardType = NSPasteboard.PasteboardType("com.prakashjoshipax.VoiceInk.transient") static func fetchSelectedText() -> String? { - // Don't check for selected text within VoiceInk itself - guard let frontmostApp = NSWorkspace.shared.frontmostApplication, - frontmostApp.bundleIdentifier != "com.prakashjoshipax.VoiceInk" else { - return nil - } let pasteboard = NSPasteboard.general let originalClipboardText = pasteboard.string(forType: .string)