I'm building a script with two hotkeys: one adds text to the beginning of each selected line, and another that adds text to the end of each selected line. Such text will come from an input box.
I've gotten it to work well for the most part — for some reason, it does not add text to the first line (beginning) and last line (end). I'm sure I'm missing something in RegExReplace(), I'm just not certain of what
Here is the script:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Add text to the beginning of each line
^+!Left::
InputBox, text, Add text to the beginning of each line, Enter text:, , 256, 125
SaveVar=%ClipboardAll%
Clipboard=
Send ^c
ClipWait, 0.5
Clipboard := RegExReplace(Clipboard, "`n", text)
Send ^v
Sleep 100
Clipboard=%SaveVar%
SaveVar=
return
; Add text to the end of each line
^+!Right::
InputBox, text, Add text to the end of each line, Enter text:, , 256, 125
SaveVar=%ClipboardAll%
Clipboard=
Send ^c
ClipWait, 0.5
Clipboard := RegExReplace(Clipboard, "`r", text)
Send ^v
Sleep 100
Clipboard=%SaveVar%
SaveVar=
return