Use selected text across all enhancement prompts and not only aiassistant prompt

This commit is contained in:
Beingpax 2025-10-05 16:53:09 +05:45
parent f8332b03fe
commit 4361597ee9
2 changed files with 13 additions and 15 deletions

View File

@ -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<CONTEXT_INFORMATION>\n\(selectedText)\n</CONTEXT_INFORMATION>"
let selectedTextContext = "\n\nSelected Text: \(selectedText)"
let generalContextSection = "\n\n<CONTEXT_INFORMATION>\(selectedTextContext)\n</CONTEXT_INFORMATION>"
let dictionaryContextSection = if !dictionaryContextService.getDictionaryContext().isEmpty {
"\n\n<DICTIONARY_CONTEXT>\(dictionaryContextService.getDictionaryContext())\n</DICTIONARY_CONTEXT>"
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

View File

@ -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)