Here is my code. Is there anything wrong with my usage of setCaretPos?
//
// Get a list of lines in code starting with
// 'function' or 'report' - this summarizes
// all the functions or reports in the program
//
function ShowFunctions() {
var edLog = newEditor();
edLog.assignActiveEditor();
var edFilter = newEditor();
edFilter.NewFile();
var s = edLog.Text();
var l = s.split("\n");
var i;
//save the editor FN in the 1st line for later retreival
var FN = edLog.fileName() + "\n";
edFilter.appendText(FN);
for (i in l)
{
var t = l[i];
if ((t.search(/function/i) == 0) ||
(t.search(/report/i) == 0)) {
edFilter.appendText(t);
}
}
}
//
// Keep the cursor on the function line that you would like
// to go to and run the script. It searches for the correct
// open filename and attempts to seek the line where the
// function starts
//
function getSelText(){
var i;
var edLog = newEditor();
edLog.assignActiveEditor();
//The search text till just before the "(" - the "("
//throws an error in search and should be avoided
var searchText = filterFuncName(edLog.lineText());
var s = edLog.Text();
var l = s.split("\n");
//first line should contain the editor file name
var FN = l[0];
FN = FN.replace(/^\s+|\s+$/g, ''); //Trim spaces
var edFilter = newEditor();
var ecount = editorsCount();
//lets hope the FN matches at least one open editor.
//Otherwise the function quits.
var AFN;
for(i=0;i<ecount;i++){
edFilter.assignEditorByIndex(i);
AFN = edFilter.fileName();
AFN = AFN.replace(/^\s+|\s+$/g, '');
if(FN==AFN)
break;
}
if (FN != AFN)
return;
edFilter.activate();
var s1 = edFilter.Text();
var l1 = s1.split("\n");
//Get the line where the function/report
//resides
var ind;
for (i in l1) {
var t = l1[i];
if (t.search(searchText) == 0){
ind = i;
break;
}
}
//now move the cursor to that line
/*
edFilter.setCaretPos(ind,0);
*/
//setCaretPos didn't work
//tedious & unreliable workaround
var PageLength = 53;
edFilter.command("ecEditorTop");
//calculate the number of pages down
var nopgdn = Math.floor(ind/PageLength);
for(i=1;i<=nopgdn;i++)
edFilter.command("ecPageDown");
//calculate the number of lines down after
//page down
nopgdn = ind%PageLength;
for(i=1;i<=nopgdn;i++)
edFilter.command("ecDown");
}
function filterFuncName(funcName){
var i = funcName.indexOf("(");
if (i > 0){
return funcName.substring(0,i-1);
}else{
return funcName;
}
}
--
<http://forum.pspad.com/read.php?2,44614,44655>
PSPad freeware editor http://www.pspad.com