Last active
January 19, 2018 10:07
-
-
Save tsaiid/b73e21d586e7d9ff96fe91a9540f3f56 to your computer and use it in GitHub Desktop.
Reorder selected text from the clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Reordering the selected text | |
ReorderSeletedText(deOrder = False, keepEmptyLine = False, itemChar = ""){ | |
Clipboard := "" | |
SendEvent ^c | |
Sleep, 300 | |
StringReplace, selectedText, Clipboard, `r`n, `n, All | |
StringRight, strRight, selectedText, 1 | |
If (Ord(strRight) == Ord("`n")) { | |
StringTrimRight, selectedText, selectedText, 1 | |
hadTrimmedRight := True | |
} | |
StringSplit, txtAry, selectedText, `n | |
endLine := txtAry0 | |
If (StrLen(selectedText) > 0) { | |
finalText := "" | |
currLineNo := 0 | |
Loop, Parse, selectedText, `n | |
{ | |
If (!RegExMatch(A_LoopField, "^\s*$")) { | |
If (!deOrder) { | |
orderChar := (StrLen(itemChar) > 0 ? itemChar : ++currLineNo . ".") | |
finalText .= orderChar . " " | |
} | |
finalText .= RegExReplace(A_LoopField, "^(\s*)((\d+\.)|([-\+\*>])|(\(?\d+\)))?(\s*)(\w?)(.*)", "$u7$8") | |
If (A_Index < endLine || hadTrimmedRight) { | |
finalText .= "`r`n" | |
} | |
} Else { | |
; use a para to control if all line is empty, ignore it, and do not append an \n | |
If (keepEmptyLine) { | |
finalText .= A_LoopField . "`r`n" | |
} | |
} | |
} | |
Clipboard := finalText | |
SendEvent ^v | |
} Else { | |
; No selection. Do nothing. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment