Enhanced Replace operation to go back to originally active segment

This script will take the user back to the segment where the Replace operation was initiated, instead of to the last segment where the Replace operation was executed, which is Studio's default behavior.

The script works by inserting some placeholder text ("markerhere") in the original segment to be found and deleted at the end of the Replace operation.

Hotkeys to run the script:

Ctrl+H - Adds "markerhere" to the active segment. Opens the Replace window. If some text is selected, it will be pasted into the "Find what" field in the Find and Replace dialog box.

Enter - Runs the "Replace all" operation, no need to click Find Next and then Replace All.

Esc - Finds and deletes the "markerhere" placeholder text, leaving the user at the originally active segment, and closes the Find and Replace dialog box.

 

#IfWinActive ahk_exe SDLTradosStudio.exe
$^h::
Send ^c
Sleep 200
Send ^a{right}
Sleep 200
Send {Space}markerhere
Sleep 100
Send ^{PgUp}
KeyWait, h
send ^h
Sleep 200
Send ^v
Sleep 100
Send {tab}
return


#IfWinActive, Find and Replace, &Find what:
Enter::
Controlclick, Find &Next, Find and Replace
Sleep 1000
Controlclick, R&eplace All, Find and Replace
Return

Esc::
WinActivate, Find and Replace
Sendinput {Space}markerhere
Sleep 200
Sendinput {tab}
Sleep 200
Sendinput {delete}
Sleep 200
Controlclick, Find &Next, Find and Replace
Sleep 1000
Controlclick, R&eplace All, Find and Replace
Sleep 500
Controlclick, &Close, Find and Replace
Sleep 200
Return
#IfWinActive