Python plugin - problem with setFirstVisibleLine
-
Hi, I have a script that finds the function declaration of the word under the cursor. E,g, in the following example, I select
A()
within function B, run the script, and it takes me to the line ofdef A():
def A(): pass def B(): A()
The problem I’m having is as follows:
I useeditor.lineFromPosition(pos)
to get the line number of the found function, and I useeditor.setFirstVisibleLine
to go to that line.
However, I realized tonight thateditor.lineFromPosition()
gives you the absolute line number of that position, buteditor.setFirstVisibleLine
doesn’t set the line to the absolute line of that number because it doesn’t take hidden lines into consideration!
To explain a little more:- if
editor.lineFromPosition()
returned 100 - Between 1 and 100, there are 10 hidden lines (by folding)
- I want line 100 to be the first visible line
editor.setFirstVisibleLine(100)
will show line 110!
I hope this is clear…
How am I supposed to overcome this???Thanks,
DaveyP.S. gotoLine(100) does work properly, but this doesn’t set it at the top of the view
- if
-
I guess you are looking for editor.gotoPos(pos)
Cheers
Claudia -
Hi Claudia,
Thanks, but this also doesn’t bring it to the top of the screen
Maybe I have to do just create my own loop to keep testing whether the line I want is at the top…??
Sounds weird… is it true?Thanks
Davey -
Hi Davey,
now I get it, never used editor.setFirstVisibleLine before
and my test was done with your ~20 lines of description, so nothing really changed by using this call with parameter 100 shameYou are right, from the documentation it looks like you have to do it
SCI_GETALLLINESVISIBLE to see if something is hidden at all.
And loop SCI_GETLINEVISIBLE(int line) to get the hidden lines, count it and … hm …
I guess it makes a difference if the hidden lines are under the line you want to be on the top or before.
So, count the lines which are before your line … or … !?Let me know - I have to go to work soon ;-)
Cheers
Claudia -
:) Thanks
It doesn’t sound right - correct?Anyway, I’ll let you know what I come out with… if I do! :)
Thanks for your help!
Davey -
no - I guess you need
editor.visibleFromDocLine
and
editor.docLineFromVisible
together with
setFirstVisibleLineCheers
Claudia -
Awesome Claudia!
Thanks a ton - I knew there had to be some better method!
You saved me a lot of time!Thank you!
Davey(P.S. I searched all the docs for Line and Visible - but I didnt see this! Weird!)
-
Both visibleFromDocLine() and docLineFromVisible()…and setFirstVisibleLine() are in the pythonscript documentation.
I’d also like to point out the pythonscript has its own discussion area separate from the Notepad++ Community one. It is found here:
https://sourceforge.net/p/npppythonscript/discussion/
I’m not saying not to post pythonscript related stuff here, just pointing that other forum out as an option. :)
-
Hi Scott, thanks
Yes, I do recognize that forum, I actually have some scripts there I think
I was actually debating for a few minutes where to post it… :)Thanks,
Davey