Python plugin - problem with setFirstVisibleLine
DaveyD last edited by DaveyD
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 of
def A(): pass def B(): A()
The problem I’m having is as follows:
editor.lineFromPosition(pos)to get the line number of the found function, and I use
editor.setFirstVisibleLineto go to that line.
However, I realized tonight that
editor.lineFromPosition()gives you the absolute line number of that position, but
editor.setFirstVisibleLinedoesn’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:
- 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???
P.S. gotoLine(100) does work properly, but this doesn’t set it at the top of the view
Claudia Frank last edited by
I guess you are looking for editor.gotoPos(pos)
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?
Claudia Frank last edited by
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 shame
You 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 ;-)
It doesn’t sound right - correct?
Anyway, I’ll let you know what I come out with… if I do! :)
Thanks for your help!
Claudia Frank last edited by Claudia Frank
no - I guess you need
Thanks a ton - I knew there had to be some better method!
You saved me a lot of time!
(P.S. I searched all the docs for Line and Visible - but I didnt see this! Weird!)
Scott Sumner last edited by
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:
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… :)