"Scroll" current line to the top of the screen
-
I’ve tried both the NPPExec and Python scripts posted in this thread but can’t get them to work.
Specifically, this
npp_console keep sci_sendmsg SCI_HOMEDISPLAY npp_sendmsg WM_COMMAND IDM_SEARCH_PREV_BOOKMARK sci_sendmsg SCI_GETCURRENTPOS sci_sendmsg SCI_LINEFROMPOSITION $(MSG_RESULT) sci_sendmsg SCI_SETFIRSTVISIBLELINE $(MSG_RESULT)
just takes me to the bottom of the file.
-
Someone might come around and guide you to your topmost line goal, but you should know that a pauper’s facsimile is super easy to achieve: a macro (with shortcut) that will move the current line up a bunch of lines.
So, for ex., say you made a 15 and a 20 line version; these would provide you a good amount of the functionality you’re hoping for.
I’ll assume you don’t need help with this, but feel free to ask.
-
@neil-schipper said in "Scroll" current line to the top of the screen:
a macro (with shortcut) that will move the current line up a bunch of lines.
I was trying to find the thread he referenced before he posted it. As well as the program solution in that thread offered by another member I had offered a macro such as you mentioned. As you say it’s a poor man’s solution.
Terry
-
If I understand your request correctly, a Python script solution looks like this
editor.setFirstVisibleLine(editor.lineFromPosition(editor.getCurrentPos()))
-
@ekopalypse Thank you very much, your script works beautifully - unless there is any folded code in the tab. This was also the reason why my former attempts led to nothing.
Unless there is a way (unlikely!) to store the state of code folding, unfold all, do what your script does, then restore the folding state, scripting apparently isn’t an option.
I guess I’ll just have to use the ‘scroll up x lines’ workaround for the time being. Thanks to the other responders for reminding me of that option.
-
Another thought has occurred. A script could determine the number of lines on the screen and then scroll up by half that number. As this would not depend on screen resolution remaining constant (as when scrolling a fixed / preset number of lines), it would serve just as well. I’ll try to work it out from the other thread unless someone beats me to it.
-
A script could determine the number of lines on the screen and then scroll up by half that number.
Indeed it could:
for n in range(editor.linesOnScreen() / 2): editor.lineScrollDown()
(This is my first not-entirely-trivial piece of Pythonscript code – a bit of research was needed, and prior to this, I’d only tweaked other people’s code with no research; also, I believe, it’s my first submitted here.)
-
@neil-schipper Excellent, thank you very much and congrats on figuring it out! Had to deduct 1 before the last closng parenthesis in the first line as otherwise the line below the current one wound up at the top. Working great now.
-
@p-cooper said in "Scroll" current line to the top of the screen:
@ekopalypse Thank you very much, your script works beautifully - unless there is any folded code in the tab.
Unless I’m misunderstanding, this will compensate for the effects of folding:
editor.setFirstVisibleLine(editor.visibleFromDocLine(editor.lineFromPosition(editor.getCurrentPos())))
-
@p-cooper said in "Scroll" current line to the top of the screen:
Working great now.
Nice to know and thanks, but Alan’s handles folded code and wrapped lines just as anyone would hope.
-
@alan-kilborn Perfect. Thanks ever so much!