Community
    • Login

    "Scroll" current line to the top of the screen

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 5 Posters 1.5k 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.
    • Neil SchipperN
      Neil Schipper @P Cooper
      last edited by

      @p-cooper

      Someone might come around and guide you to your topmost line goal, but you should know that a pauper’s facsimile is super easy to achieve: a macro (with shortcut) that will move the current line up a bunch of lines.

      So, for ex., say you made a 15 and a 20 line version; these would provide you a good amount of the functionality you’re hoping for.

      I’ll assume you don’t need help with this, but feel free to ask.

      Terry RT 1 Reply Last reply Reply Quote 2
      • Terry RT
        Terry R @Neil Schipper
        last edited by

        @neil-schipper said in "Scroll" current line to the top of the screen:

        a macro (with shortcut) that will move the current line up a bunch of lines.

        I was trying to find the thread he referenced before he posted it. As well as the program solution in that thread offered by another member I had offered a macro such as you mentioned. As you say it’s a poor man’s solution.

        Terry

        1 Reply Last reply Reply Quote 2
        • EkopalypseE
          Ekopalypse @P Cooper
          last edited by

          @p-cooper

          If I understand your request correctly, a Python script solution looks like this

          editor.setFirstVisibleLine(editor.lineFromPosition(editor.getCurrentPos()))
          
          P CooperP 1 Reply Last reply Reply Quote 3
          • P CooperP
            P Cooper @Ekopalypse
            last edited by

            @ekopalypse Thank you very much, your script works beautifully - unless there is any folded code in the tab. This was also the reason why my former attempts led to nothing.

            Unless there is a way (unlikely!) to store the state of code folding, unfold all, do what your script does, then restore the folding state, scripting apparently isn’t an option.

            I guess I’ll just have to use the ‘scroll up x lines’ workaround for the time being. Thanks to the other responders for reminding me of that option.

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • P CooperP
              P Cooper
              last edited by

              Another thought has occurred. A script could determine the number of lines on the screen and then scroll up by half that number. As this would not depend on screen resolution remaining constant (as when scrolling a fixed / preset number of lines), it would serve just as well. I’ll try to work it out from the other thread unless someone beats me to it.

              Neil SchipperN 1 Reply Last reply Reply Quote 0
              • Neil SchipperN
                Neil Schipper @P Cooper
                last edited by

                @p-cooper

                A script could determine the number of lines on the screen and then scroll up by half that number.

                Indeed it could:

                for n in range(editor.linesOnScreen() / 2):
                    editor.lineScrollDown()
                

                (This is my first not-entirely-trivial piece of Pythonscript code – a bit of research was needed, and prior to this, I’d only tweaked other people’s code with no research; also, I believe, it’s my first submitted here.)

                P CooperP 1 Reply Last reply Reply Quote 3
                • P CooperP
                  P Cooper @Neil Schipper
                  last edited by

                  @neil-schipper Excellent, thank you very much and congrats on figuring it out! Had to deduct 1 before the last closng parenthesis in the first line as otherwise the line below the current one wound up at the top. Working great now.

                  Neil SchipperN 1 Reply Last reply Reply Quote 1
                  • Alan KilbornA
                    Alan Kilborn @P Cooper
                    last edited by

                    @p-cooper said in "Scroll" current line to the top of the screen:

                    @ekopalypse Thank you very much, your script works beautifully - unless there is any folded code in the tab.

                    Unless I’m misunderstanding, this will compensate for the effects of folding:

                    editor.setFirstVisibleLine(editor.visibleFromDocLine(editor.lineFromPosition(editor.getCurrentPos())))

                    P CooperP 1 Reply Last reply Reply Quote 5
                    • Neil SchipperN
                      Neil Schipper @P Cooper
                      last edited by

                      @p-cooper said in "Scroll" current line to the top of the screen:

                      Working great now.

                      Nice to know and thanks, but Alan’s handles folded code and wrapped lines just as anyone would hope.

                      1 Reply Last reply Reply Quote 2
                      • P CooperP
                        P Cooper @Alan Kilborn
                        last edited by

                        @alan-kilborn Perfect. Thanks ever so much!

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