• Login
Community
  • Login

"Scroll" current line to the top of the screen

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
12 Posts 5 Posters 1.4k 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.
  • P
    P Cooper
    last edited by Jun 1, 2022, 8:25 AM

    Hi.

    I’d like a scroll-type command to make the current line (where the cursor is) the topmost line of the visible part of the file / the current view. Say, cursor is on line 50 and the topmost line shown on the screen is line 30, when I execute the command, whoosh, line 50 become the topmost line on screen.

    Many thanks!

    N 1 Reply Last reply Jun 1, 2022, 9:08 AM Reply Quote 0
    • P
      P Cooper
      last edited by P Cooper Jun 1, 2022, 8:53 AM Jun 1, 2022, 8:50 AM

      I’ve tried both the NPPExec and Python scripts posted in this thread but can’t get them to work.

      Specifically, this

      npp_console keep
      
      sci_sendmsg SCI_HOMEDISPLAY
      npp_sendmsg WM_COMMAND IDM_SEARCH_PREV_BOOKMARK
      
      sci_sendmsg SCI_GETCURRENTPOS
      sci_sendmsg SCI_LINEFROMPOSITION $(MSG_RESULT)
      sci_sendmsg SCI_SETFIRSTVISIBLELINE $(MSG_RESULT)
      

      just takes me to the bottom of the file.

      E 1 Reply Last reply Jun 1, 2022, 9:19 AM Reply Quote 0
      • N
        Neil Schipper @P Cooper
        last edited by Jun 1, 2022, 9:08 AM

        @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.

        T 1 Reply Last reply Jun 1, 2022, 9:15 AM Reply Quote 2
        • T
          Terry R @Neil Schipper
          last edited by Jun 1, 2022, 9:15 AM

          @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
          • E
            Ekopalypse @P Cooper
            last edited by Jun 1, 2022, 9:19 AM

            @p-cooper

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

            editor.setFirstVisibleLine(editor.lineFromPosition(editor.getCurrentPos()))
            
            P 1 Reply Last reply Jun 1, 2022, 9:50 AM Reply Quote 3
            • P
              P Cooper @Ekopalypse
              last edited by Jun 1, 2022, 9:50 AM

              @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.

              A 1 Reply Last reply Jun 1, 2022, 11:58 AM Reply Quote 0
              • P
                P Cooper
                last edited by Jun 1, 2022, 9:56 AM

                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.

                N 1 Reply Last reply Jun 1, 2022, 11:02 AM Reply Quote 0
                • N
                  Neil Schipper @P Cooper
                  last edited by Jun 1, 2022, 11:02 AM

                  @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 1 Reply Last reply Jun 1, 2022, 11:54 AM Reply Quote 3
                  • P
                    P Cooper @Neil Schipper
                    last edited by Jun 1, 2022, 11:54 AM

                    @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.

                    N 1 Reply Last reply Jun 1, 2022, 12:48 PM Reply Quote 1
                    • A
                      Alan Kilborn @P Cooper
                      last edited by Jun 1, 2022, 11:58 AM

                      @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 1 Reply Last reply Jun 1, 2022, 5:50 PM Reply Quote 5
                      • N
                        Neil Schipper @P Cooper
                        last edited by Jun 1, 2022, 12:48 PM

                        @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
                          P Cooper @Alan Kilborn
                          last edited by Jun 1, 2022, 5:50 PM

                          @alan-kilborn Perfect. Thanks ever so much!

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