-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextediting.ahk
202 lines (154 loc) · 3.65 KB
/
textediting.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#Requires AutoHotkey v2.0
#SingleInstance force
RunDialogue(arg, useSingleChar)
{
SendText "{ }"
SendInput("{Left 2}")
ArgObj := FileOpen(".\type_shortcut_args.txt", "w")
ArgObj.Write(arg "`n1" "`n" (useSingleChar?"1":"0"))
ArgObj.Close()
RunWait "./type_shortcut.exe"
OutputObj := FileOpen(".\type_shortcut_output.txt", "r")
Line := OutputObj.Read()
OutputObj.Close()
SendInput("{Delete 2}{Backspace 2}")
return Line
}
#HotIf !GetKeyState("Shift")
{
F24 & f::MoveNext()
F24 & b::SelectInside()
}
#HotIf GetKeyState("Shift")
{
F24 & f::MovePrevious()
}
MoveNext()
{
txt := RunDialogue("next", false)
if txt == "`b" || txt == ""
return
position := FindNext(txt)
if (position > 0) {
SendInput "{Right " . (position - 1) . "}"
}
SendInput "{Ctrl down}{Up 10}{Ctrl up}"
}
MovePrevious()
{
txt := RunDialogue("prev", false)
if txt == "`b" || txt == ""
return
position := FindPrevious(txt)
if (position > 0) {
SendInput "{Left " . (position) . "}"
}
SendInput "{Ctrl down}{Down 10}{Ctrl up}"
}
FindNext(txt)
{
SendInput "{Ctrl down}{Shift down}{End}{Shift up}{Ctrl up}"
Sleep 20
SendInput "{Ctrl down}{c}{Ctrl up}"
Sleep 20
SendInput "{Left}"
content := StrReplace(A_Clipboard, "`r", "")
position := InStr(content, txt, true, 1)
return position
}
FindPrevious(txt)
{
SendInput "{}"
SendInput "{Ctrl down}{Shift down}{Home}{Shift up}{Ctrl up}"
Sleep 20
SendInput "{Ctrl down}{c}{Ctrl up}"
Sleep 20
SendInput "{Right}"
content := StrReplace(A_Clipboard, "`r", "")
position := InStr(content, txt, true, -1)
position := (StrLen(content) - position) + 1 - StrLen(txt)
return position
}
FindSecondPair(secondPair, firstPair)
{
if secondPair == firstPair
return FindNext(secondPair)
SendInput "{Ctrl down}{Shift down}{End}{Shift up}{Ctrl up}"
Sleep 20
SendInput "{Ctrl down}{c}{Ctrl up}"
Sleep 20
SendInput "{Left}"
content := StrReplace(A_Clipboard, "`r", "")
delta := 1
For i, char in StrSplit(content, "")
{
if char == firstPair
delta++
if char == secondPair
delta--
if delta == 0
return i
}
return 0
}
FindFirstPair(firstPair, secondPair)
{
if firstPair == secondPair
return FindPrevious(firstPair)
SendInput "{Ctrl down}{Shift down}{Home}{Shift up}{Ctrl up}"
Sleep 20
SendInput "{Ctrl down}{c}{Ctrl up}"
Sleep 20
SendInput "{Right}"
content := StrReplace(A_Clipboard, "`r", "")
delta := 1
i := StrLen(content)
While (i > 0)
{
char := SubStr(content, i, 1)
if char == secondPair
delta++
if char == firstPair
delta--
if delta == 0
return StrLen(content) - i
i--
}
return -1
}
SelectInside()
{
a := RunDialogue("inside", true)
if a == "`b" || a == ""
return
b := ""
Switch a
{
Case "(":
b := ")"
Case "[":
b := "]"
Case "{":
b := "}"
Case "<":
b := ">"
Case "'":
b := "'"
Case "`"":
b := "`""
}
if b == ""
return
posA := FindFirstPair(a, b)
if (posA < 0)
return
Sleep 20
SendInput "{Left " . (posA) . "}"
Sleep 100
posB := FindSecondPair(b, a)
if (posB <= 0)
return
Sleep 20
SendInput "{Shift down}{Right " . (posB - 1) . "}{Shift up}"
SendInput "{Ctrl down}{Up 10}{Ctrl up}"
}