-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-blank-line.ahk
76 lines (59 loc) · 1.34 KB
/
remove-blank-line.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#Requires AutoHotkey v2.0
#SingleInstance Force
KeyHistory 0
SendMode "Input"
global debug := False ;debug 输出开关
getTextSelected() {
A_Clipboard := ""
Sleep 10
Send "^c"
Sleep 10
if !ClipWait(2) ; 最多等待 x s
{
MsgBox "剪切板操作失败。确保您选中了文本"
return
}
global debug
if debug {
MsgBox A_Clipboard
}
return A_Clipboard
}
paste(text) {
A_Clipboard := text
Sleep 10
Send "^v"
}
trimOneBlankLine(text) {
text := StrReplace(text, "`r`n`r`n", "`r`n")
text := StrReplace(text, "`r`n", "`r`n")
text := StrReplace(text, "`n`n", "`r`n")
text := StrReplace(text, "`r", "")
return text
}
trimAllBlankLine(text) {
text := StrReplace(text, "`r`n`r`n", "`r`n")
text := StrReplace(text, "`r`n", "`r`n")
newContent := ""
Loop parse, text, "`n", "`r"
{
line := A_LoopField
lineTrim := Trim(line)
if (lineTrim != "")
newContent .= A_LoopField "`r`n"
}
return newContent
}
#HotIf WinActive("ahk_exe winword.exe") or WinActive("ahk_exe wps.exe")
^+s:: {
Send "^a" ; 全自动。
text := getTextSelected()
text := trimAllBlankLine(text)
paste(text)
}
F4:: {
text := getTextSelected()
text := trimOneBlankLine(text)
paste(text)
}
#HotIf