Skip to content

Commit d8f170a

Browse files
authored
Merge pull request #8 from Rod-Gomes/patch-1
Enhancements to Handle Selected Text and Error Prevention
2 parents 8fca4a8 + a567602 commit d8f170a

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

AI-Tools.ahk

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,20 @@ PromptHandler(promptName, append := false) {
7272
global _running := true
7373
global _startTime := A_TickCount
7474

75-
ShowWaitTooltip()
76-
SetSystemCursor(GetSetting("settings", "cursor_wait_file", "wait"))
77-
7875
prompt := GetSetting(promptName, "prompt")
7976
promptEnd := GetSetting(promptName, "prompt_end")
8077
mode := GetSetting(promptName, "mode", GetSetting("settings", "default_mode"))
81-
input := GetTextFromClip()
78+
79+
try {
80+
input := GetTextFromClip()
81+
} catch {
82+
global _running := false
83+
RestoreCursor()
84+
return
85+
}
8286

87+
ShowWaitTooltip()
88+
SetSystemCursor(GetSetting("settings", "cursor_wait_file", "wait"))
8389
CallAPI(mode, promptName, prompt, input, promptEnd)
8490

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

95101
SelectText() {
96-
if WinActive("ahk_exe WINWORD.EXE") or
97-
WinActive("ahk_exe OUTLOOK.EXE") {
98-
; In Word/Outlook select the current paragraph
99-
Send "^{Up}^+{Down}+{Left}" ; Move to para start, select para, move left to not include para end
100-
} else if WinActive("ahk_exe notepad++.exe") or
101-
WinActive("ahk_exe Code.exe") {
102-
; In Notepad++ select the current line
103-
Send "{End}{End}+{Home}+{Home}"
104-
} else {
105-
Send "^a"
102+
Send "^c"
103+
ClipWait(2)
104+
text := A_Clipboard
105+
if StrLen(text) < 1 {
106+
if WinActive("ahk_exe WINWORD.EXE") or WinActive("ahk_exe OUTLOOK.EXE") {
107+
; In Word/Outlook select the current paragraph
108+
Send "^{Up}^+{Down}+{Left}" ; Move to para start, select para, move left to not include para end
109+
} else if WinActive("ahk_exe notepad++.exe") or WinActive("ahk_exe Code.exe") {
110+
; In Notepad++ select the current line
111+
Send "{End}{End}+{Home}+{Home}"
112+
} else {
113+
; Select all text if no text is selected
114+
Send "^a"
115+
}
106116
}
107117
sleep 50
108118
}
@@ -118,6 +128,7 @@ GetTextFromClip() {
118128
text := A_Clipboard
119129

120130
if StrLen(text) < 1 {
131+
ShowWarning("No text selected. Please select text and try again.")
121132
throw ValueError("No text selected", -1)
122133
} else if StrLen(text) > 16000 {
123134
throw ValueError("Text is too long", -1)
@@ -126,6 +137,10 @@ GetTextFromClip() {
126137
return text
127138
}
128139

140+
ShowWarning(message) {
141+
MsgBox message
142+
}
143+
129144
GetSetting(section, key, defaultValue := "") {
130145
global _settingsCache
131146
if (_settingsCache.Has(section . key . defaultValue)) {
@@ -432,4 +447,4 @@ LogDebug(msg) {
432447
logMsg := "[" . now . "] " . msg . "`n"
433448
FileAppend(logMsg, "./debug.log")
434449
}
435-
}
450+
}

0 commit comments

Comments
 (0)