Community
    • 登入

    Python plugin - problem with setFirstVisibleLine

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    9 貼文 3 Posters 5.0k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • DaveyDD
      DaveyD
      最後由 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 條回覆 最後回覆 回覆 引用 0
      • Claudia FrankC
        Claudia Frank @DaveyD
        最後由 編輯

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

        Cheers
        Claudia

        1 條回覆 最後回覆 回覆 引用 0
        • DaveyDD
          DaveyD
          最後由 編輯

          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 條回覆 最後回覆 回覆 引用 0
          • Claudia FrankC
            Claudia Frank @DaveyD
            最後由 編輯

            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 條回覆 最後回覆 回覆 引用 0
            • DaveyDD
              DaveyD
              最後由 編輯

              :) 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 條回覆 最後回覆 回覆 引用 0
              • Claudia FrankC
                Claudia Frank @DaveyD
                最後由 Claudia Frank 編輯

                no - I guess you need

                editor.visibleFromDocLine
                and
                editor.docLineFromVisible
                together with
                setFirstVisibleLine

                Cheers
                Claudia

                1 條回覆 最後回覆 回覆 引用 1
                • DaveyDD
                  DaveyD
                  最後由 編輯

                  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 條回覆 最後回覆 回覆 引用 0
                  • Scott SumnerS
                    Scott Sumner
                    最後由 編輯

                    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 條回覆 最後回覆 回覆 引用 0
                    • DaveyDD
                      DaveyD
                      最後由 編輯

                      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 條回覆 最後回覆 回覆 引用 0
                      • 第一個貼文
                        最後的貼文
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors