You are here: PSPad forum > English discussion forum > Go To Line
Posted by: pythonui | Date: 2015-09-26 06:24 | IP: IP Logged
Hello,
I need to run 'Go To Line' functionality from scripting. Is there any function or action for same ?
Thanks
Posted by: pspad | Date: 2015-09-26 07:32 | IP: IP Logged
In the script you can use cursor position directly. Look at setCaretPos(x, y) or caretX(), caretY() method
Posted by: pythonui | Date: 2015-09-26 08:50 | IP: IP Logged
Yes !
setCaretPos(x, y)
working great but its not set the center of editor ..
Any workaround ?
Posted by: pspad | Date: 2015-09-26 09:56 | IP: IP Logged
topLineIndex(), linesInWindow()
I hope you understand hwo to use it.
For more information see Scripting.rtf in PSPad folder or PSPad help
Posted by: vbr | Date: 2015-09-26 10:19 | IP: IP Logged
pythonui:Yes !
setCaretPos(x, y)
working great but its not set the center of editor ..Any workaround ?
Hi,
you could probably use something like the following hack
Quote:function setCaretAndScrollToView(){
if (editorsCount()<1){return;}
var actEd = newEditor();
actEd.assignActiveEditor();
actEd.setCaretPos(1, 1);
actEd.setCaretPos(1, 94 + Math.floor(actEd.linesInWindow()/2));
actEd.setCaretPos(7, 94);
}
i.e. set the caret to the top to ensure the direction of the scrolling (top-bottom, aligning to the bottom margin)
- set the caret about half the visible line count further
- set the caret to the needed coordinates
hth,
vbr
Edited 1 time(s). Last edit at 2015-09-26 10:29 by vbr.
Posted by: pspad | Date: 2015-09-26 11:22 | IP: IP Logged
VBR, better is use topLineIndex() funstion.
You know number of lines in the window - linesInWindow()
Half of it is center line - caretY position. So you need to set top line to CaretY position - half of the lines in window
Posted by: vbr | Date: 2015-09-26 11:56 | IP: IP Logged
pspad:VBR, better is use topLineIndex() funstion.
You know number of lines in the window - linesInWindow()
Half of it is center line - caretY position. So you need to set top line to CaretY position - half of the lines in window
Thanks for your suggestion; however, can you elaborate on the usage in the script? - I can't find a way with less code than above and possibly without repeated caret settings.
One could possibly check whether the current view (via topLineIndex) is below or above the needed caret position and adjust the half-page offset to the needed direction, but it seems a bit more complicated than the above.
vbr
Posted by: pspad | Date: 2015-09-26 12:31 | IP: IP Logged
One line less
Quote:function setCaretAndScrollToView(){
if (editorsCount()<1){return;}
var actEd = newEditor();
actEd.assignActiveEditor();
actEd.setCaretPos(1, 45);
actEd.topLineIndex(45 - Math.floor(actEd.linesInWindow()/2));
}
Posted by: vbr | Date: 2015-09-26 13:58 | IP: IP Logged
Ok, thanks,
I forgot, we can even set topLine this way (not only determine the value).
vbr
Posted by: pythonui | Date: 2015-09-28 03:48 | IP: IP Logged
Quote:One line lessQuote:
function setCaretAndScrollToView(){
if (editorsCount()<1){return;}
var actEd = newEditor();
actEd.assignActiveEditor();
actEd.setCaretPos(1, 45);
actEd.topLineIndex(45 - Math.floor(actEd.linesInWindow()/2));
}
That's perfect
Edited 1 time(s). Last edit at 2015-09-28 03:48 by pythonui.
Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR