With the msgbox at the bottom of the function, you can see that the static vars are incrementing with left/right presses, and they are getting pushed into the arrays, but it appears that the "undo" part of the arrays is not setting the static variables to previous states.
Any ideas why not? (I can explain more if needed.)
(Note: I realize that the text control doesn't get updated in the 'undo' block... I just haven't gotten that far yet.)
Code: Select all
#SingleInstance
#Requires AutoHotkey v2+
; text experiment
guiTitle := 'Trimulator (trim simulator)'
str := 'left and right arrows will visually simulate trims'
str := ' ' str ' '
delL := ']' ; delimiter left
delR := '[' ; delimiter right
undoArrL := []
undoArrR := []
mg := Gui(, guiTitle)
mg.SetFont('s16','Consolas')
delta := mg.Add('text', '-wrap cBlue', str)
mg.Show()
mg.OnEvent('Close', (*)=>ExitApp())
#hotif WinActive(guiTitle)
Right::delta.Text := Changer(delta.Text, 'Left')
Left::delta.Text := Changer(delta.Text, 'Right')
^z::delta.Text := Changer(delta.Text, 'Undo')
Esc::ExitApp()
!r::Reload()
#hotif
Changer(txt, direction)
{ static delPosL := 0 ; delimiter position left
static delPosR := 0 ; delimiter position right
undoArrL.push(delPosL) ; undo array left
undoArrR.push(delPosR) ; undo array right
If direction = "Left"
{
delPosL++
static tempL := StrReplace(LTrim(txt), delR, '')
txt := subStr(tempL, 1, delPosL) delL subStr(tempL, delPosL+1)
}
Else If direction = "Right"
{
delPosR++
static tempR := StrReplace(RTrim(txt), delL, '')
txt := subStr(tempR, 1, StrLen(tempR)-delPosR) delR subStr(tempR, (StrLen(tempR)-delPosR)+1)
}
Else If direction = "Undo"
{
If undoArrL.Length > 1 ; both will be same length, so use either.
{
undoArrL.pop ; removes and returns last array item.
delPosL := undoArrL[undoArrL.Length]
undoArrR.pop ; removes and returns last array item.
delPosR := undoArrR[undoArrR.Length]
}
}
msgbox 'L ' delPosL '`nR ' delPosR '`n`nL len ' undoArrL.Length '`nR len ' undoArrR.Length
Return txt
}