• Login
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.
  • D
    DaveyD
    last edited by DaveyD Jan 11, 2016, 2:19 AM Jan 11, 2016, 2:18 AM

    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

    C 1 Reply Last reply Jan 11, 2016, 3:10 AM Reply Quote 0
    • C
      Claudia Frank @DaveyD
      last edited by Jan 11, 2016, 3:10 AM

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

      Cheers
      Claudia

      1 Reply Last reply Reply Quote 0
      • D
        DaveyD
        last edited by Jan 11, 2016, 3:16 AM

        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

        C 2 Replies Last reply Jan 11, 2016, 3:28 AM Reply Quote 0
        • C
          Claudia Frank @DaveyD
          last edited by Jan 11, 2016, 3:28 AM

          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
          • D
            DaveyD
            last edited by Jan 11, 2016, 3:35 AM

            :) 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
            • C
              Claudia Frank @DaveyD
              last edited by Claudia Frank Jan 11, 2016, 3:38 AM Jan 11, 2016, 3:35 AM

              no - I guess you need

              editor.visibleFromDocLine
              and
              editor.docLineFromVisible
              together with
              setFirstVisibleLine

              Cheers
              Claudia

              1 Reply Last reply Reply Quote 1
              • D
                DaveyD
                last edited by Jan 11, 2016, 3:39 AM

                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
                • S
                  Scott Sumner
                  last edited by Jan 11, 2016, 11:51 AM

                  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
                  • D
                    DaveyD
                    last edited by Jan 11, 2016, 2:35 PM

                    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
                    8 out of 9
                    • First post
                      8/9
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors