Community
    • Login

    Python plugin - problem with setFirstVisibleLine

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 3 Posters 4.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DaveyDD
      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():

      def A():
          pass
      
      def B():
          A()
      

      The problem I’m having is as follows:
      I use editor.lineFromPosition(pos) to get the line number of the found function, and I use editor.setFirstVisibleLine to go to that line.
      However, I realized tonight that editor.lineFromPosition() gives you the absolute line number of that position, but editor.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,
      Davey

      P.S. gotoLine(100) does work properly, but this doesn’t set it at the top of the view

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @DaveyD
        last edited by

        I guess you are looking for editor.gotoPos(pos)

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • DaveyDD
          DaveyD
          last edited by

          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

          Claudia FrankC 2 Replies Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @DaveyD
            last edited by

            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 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 ;-)

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • DaveyDD
              DaveyD
              last edited by

              :) 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

              1 Reply Last reply Reply Quote 0
              • Claudia FrankC
                Claudia Frank @DaveyD
                last edited by Claudia Frank

                no - I guess you need

                editor.visibleFromDocLine
                and
                editor.docLineFromVisible
                together with
                setFirstVisibleLine

                Cheers
                Claudia

                1 Reply Last reply Reply Quote 1
                • DaveyDD
                  DaveyD
                  last edited by

                  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!)

                  1 Reply Last reply Reply Quote 0
                  • Scott SumnerS
                    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:

                    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. :)

                    1 Reply Last reply Reply Quote 0
                    • DaveyDD
                      DaveyD
                      last edited by

                      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

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors