Skip to content

Commit

Permalink
Merge pull request #8 from Rod-Gomes/patch-1
Browse files Browse the repository at this point in the history
Enhancements to Handle Selected Text and Error Prevention
  • Loading branch information
ecornell authored Aug 9, 2024
2 parents 8fca4a8 + a567602 commit d8f170a
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions AI-Tools.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ PromptHandler(promptName, append := false) {
global _running := true
global _startTime := A_TickCount

ShowWaitTooltip()
SetSystemCursor(GetSetting("settings", "cursor_wait_file", "wait"))

prompt := GetSetting(promptName, "prompt")
promptEnd := GetSetting(promptName, "prompt_end")
mode := GetSetting(promptName, "mode", GetSetting("settings", "default_mode"))
input := GetTextFromClip()

try {
input := GetTextFromClip()
} catch {
global _running := false
RestoreCursor()
return
}

ShowWaitTooltip()
SetSystemCursor(GetSetting("settings", "cursor_wait_file", "wait"))
CallAPI(mode, promptName, prompt, input, promptEnd)

} catch as err {
Expand All @@ -93,16 +99,20 @@ PromptHandler(promptName, append := false) {
;###

SelectText() {
if WinActive("ahk_exe WINWORD.EXE") or
WinActive("ahk_exe OUTLOOK.EXE") {
; In Word/Outlook select the current paragraph
Send "^{Up}^+{Down}+{Left}" ; Move to para start, select para, move left to not include para end
} else if WinActive("ahk_exe notepad++.exe") or
WinActive("ahk_exe Code.exe") {
; In Notepad++ select the current line
Send "{End}{End}+{Home}+{Home}"
} else {
Send "^a"
Send "^c"
ClipWait(2)
text := A_Clipboard
if StrLen(text) < 1 {
if WinActive("ahk_exe WINWORD.EXE") or WinActive("ahk_exe OUTLOOK.EXE") {
; In Word/Outlook select the current paragraph
Send "^{Up}^+{Down}+{Left}" ; Move to para start, select para, move left to not include para end
} else if WinActive("ahk_exe notepad++.exe") or WinActive("ahk_exe Code.exe") {
; In Notepad++ select the current line
Send "{End}{End}+{Home}+{Home}"
} else {
; Select all text if no text is selected
Send "^a"
}
}
sleep 50
}
Expand All @@ -118,6 +128,7 @@ GetTextFromClip() {
text := A_Clipboard

if StrLen(text) < 1 {
ShowWarning("No text selected. Please select text and try again.")
throw ValueError("No text selected", -1)
} else if StrLen(text) > 16000 {
throw ValueError("Text is too long", -1)
Expand All @@ -126,6 +137,10 @@ GetTextFromClip() {
return text
}

ShowWarning(message) {
MsgBox message
}

GetSetting(section, key, defaultValue := "") {
global _settingsCache
if (_settingsCache.Has(section . key . defaultValue)) {
Expand Down Expand Up @@ -432,4 +447,4 @@ LogDebug(msg) {
logMsg := "[" . now . "] " . msg . "`n"
FileAppend(logMsg, "./debug.log")
}
}
}

0 comments on commit d8f170a

Please sign in to comment.