Skip to content

Commit b53bd13

Browse files
committed
Fix paste issue
1 parent ff76fae commit b53bd13

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

AI-Tools.ahk

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ 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+
7578
prompt := GetSetting(promptName, "prompt")
7679
promptEnd := GetSetting(promptName, "prompt_end")
7780
mode := GetSetting(promptName, "mode", GetSetting("settings", "default_mode"))
@@ -84,8 +87,6 @@ PromptHandler(promptName, append := false) {
8487
return
8588
}
8689

87-
ShowWaitTooltip()
88-
SetSystemCursor(GetSetting("settings", "cursor_wait_file", "wait"))
8990
CallAPI(mode, promptName, prompt, input, promptEnd)
9091

9192
} catch as err {
@@ -99,19 +100,22 @@ PromptHandler(promptName, append := false) {
99100
;###
100101

101102
SelectText() {
103+
global _oldClipboard := A_Clipboard
104+
102105
A_Clipboard := ""
103106
Send "^c"
104107
ClipWait(2)
105108
text := A_Clipboard
106-
if StrLen(text) < 1 {
107-
if WinActive("ahk_exe WINWORD.EXE") or WinActive("ahk_exe OUTLOOK.EXE") {
108-
; In Word/Outlook select the current paragraph
109-
Send "^{Up}^+{Down}+{Left}" ; Move to para start, select para, move left to not include para end
110-
} else if WinActive("ahk_exe notepad++.exe") or WinActive("ahk_exe Code.exe") {
111-
; In Notepad++ select the current line
112-
Send "{End}{End}+{Home}+{Home}"
113-
} else {
114-
; Select all text if no text is selected
109+
110+
if WinActive("ahk_exe WINWORD.EXE") or WinActive("ahk_exe OUTLOOK.EXE") {
111+
; In Word/Outlook select the current paragraph
112+
Send "^{Up}^+{Down}+{Left}" ; Move to para start, select para, move left to not include para end
113+
} else if WinActive("ahk_exe notepad++.exe") or WinActive("ahk_exe Code.exe") {
114+
; In Notepad++ select the current line
115+
Send "{End}{End}+{Home}+{Home}"
116+
} else {
117+
; Select all text if no text is selected
118+
if StrLen(text) < 1 {
115119
Send "^a"
116120
}
117121
}
@@ -121,15 +125,16 @@ SelectText() {
121125
GetTextFromClip() {
122126

123127
global _activeWin := WinGetTitle("A")
124-
global _oldClipboard := A_Clipboard
128+
if _oldClipboard == "" {
129+
global _oldClipboard := A_Clipboard
130+
}
125131

126132
A_Clipboard := ""
127133
Send "^c"
128134
ClipWait(2)
129135
text := A_Clipboard
130136

131137
if StrLen(text) < 1 {
132-
ShowWarning("No text selected. Please select text and try again.")
133138
throw ValueError("No text selected", -1)
134139
} else if StrLen(text) > 16000 {
135140
throw ValueError("Text is too long", -1)
@@ -202,10 +207,6 @@ GetBody(mode, promptName, prompt, input, promptEnd) {
202207
}
203208

204209
CallAPI(mode, promptName, prompt, input, promptEnd) {
205-
if (StrLen(input) < 1) {
206-
; Input is too short. No request will be made to the API.
207-
return
208-
}
209210

210211
body := GetBody(mode, promptName, prompt, input, promptEnd)
211212
bodyJson := Jxon_dump(body, 4)
@@ -242,16 +243,19 @@ CallAPI(mode, promptName, prompt, input, promptEnd) {
242243
MsgBox "Error: Status " req.status " - " req.responseText, , 16
243244
return
244245
}
245-
} catch {
246+
} catch as e {
246247
RestoreCursor()
247248
global _running := false
248-
MsgBox "Error: Unable to connect to the API. Please check your internet connection and try again.", , 16
249+
MsgBox "Error: " "Exception thrown!`n`nwhat: " e.what "`nfile: " e.file
250+
. "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra, , 16
249251
return
250252
}
251253
}
252254

253255
HandleResponse(data, mode, promptName, input) {
254256

257+
global _oldClipboard
258+
255259
Gui_Size(thisGui, MinMax, Width, Height)
256260
{
257261
if MinMax = -1 ; The window has been minimized. No action needed.
@@ -329,11 +333,12 @@ HandleResponse(data, mode, promptName, input) {
329333
}
330334

331335
global _running := false
332-
Sleep 500
333-
A_Clipboard := _oldClipboard
334-
336+
Sleep 500
337+
335338
} finally {
336339
global _running := false
340+
A_Clipboard := _oldClipboard
341+
global _oldClipboard := ""
337342
RestoreCursor()
338343
}
339344
}
@@ -466,4 +471,4 @@ LogDebug(msg) {
466471
logMsg := "[" . now . "] " . msg . "`n"
467472
FileAppend(logMsg, "./debug.log")
468473
}
469-
}
474+
}

0 commit comments

Comments
 (0)