vvume: -------------------------------------------------------------------------------- Here is my code. Is there anything wrong with my usage of setCaretPos? ... //now move the cursor to that line /* edFilter.setCaretPos(ind,0); */ //setCaretPos didn't work //tedious & unreliable workaround ... --------------------------------------------------------------------------------
I guess, the indices to setCaretPos are 1-based (as are the caretX, caretY functions or the statusbar information in PSPad. The caret is placed on the given line before the character with given index (both counting from 1). The very beginning of the text has coordinates (1,1) for some reason, if you use setCaretPos(0,2) it behaves identicaly to setCaretPos(1,2) - ie. caret before the first character of the second line; however, zero as y-parameter sets the caret at the beginning of the file (1,1). That might be, what is happenning in your script; does it work better, if you use edFilter.setCaretPos(ind,1); ? or maybe edFilter.setCaretPos(1,ind); if you want to set the caret at the beginning of the line with number ind (x - column; y - line). (As a sidenote, setting any coordinate to -1 causes no change in that direction.) http://gogogadgetscott.info/pspad/functions.htm#setCaretPos You may try to experiment with a simple script like this: cite: -------------------------------------------------------------------------------- var module_name = "test_setCaret"; var module_ver = "0.0.1"; function setCaret(){ if (editorsCount()<1){return;} var actEd = newEditor(); actEd.assignActiveEditor(); echo ("Current caret coordinates:\nline: " + actEd.caretY() + "; col: " + actEd.caretX()); carY = InputText("set line (caretY): ", ""); carX = InputText("set column (caretX): ", ""); actEd.setCaretPos(carX,carY); } function Init(){ addMenuItem("setCaret", "", "setCaret","Ctrl+Alt+A"); } -------------------------------------------------------------------------------- (possibly the linebreak in the line with "echo" will need to be removed) -- <http://forum.pspad.com/read.php?2,44614,44668> PSPad freeware editor http://www.pspad.com
