Community
    • Login

    Get undo to scroll to context

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 263 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
      page200
      last edited by

      When using the undo/redo feature, Notepad++ scrolls to the line where the change happened but not further. So I don’t see the lines above or below it.

      How do I make it automatically scroll such that I see lines above and below the change? So how do I make it scroll the changed line to the center of the screen rather than the top or bottom of the screen?

      1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones
        last edited by PeterJones

        @page200 ,

        As you have guessed from two weeks with no reply, Notepad++ doesn’t have that feature.

        I’m sorry no one had replied yet. Sometimes that happens if no one has a good idea right away.

        I didn’t have time two weeks ago, but I did today, so I hacked up a pair of scripts for the PythonScript plugin.

        1. Install PythonScript 3.0.22 or later per the PythonScript 3.0.x instructions in our PythonScript FAQ
        2. Create and populate the new script undo_and_scroll.py using the source below and the instructions for “create” and “populate” in the FAQ
        3. Create and populate the new script redo_and_scroll.py using the second source below and the same instructions
        4. Verify them using Plugins > Python Script > Scripts > undo_and_scroll or redo_and_scroll
        5. Once they are working, if you want, you can follow the FAQ instructions to create a shortcut for each (you could replace the Ctrl+Z and Ctrl+Y – but you’d have to use the shortcut mapper on the Scintilla commands page to remove those shortcuts from SCI_UNDO and SCI_REDO)

        undo_and_scroll.py:

        # encoding=utf-8
        """in response to https://community.notepad-plus-plus.org/topic/27122/
        
        This does the UNDO then tries to scroll to approximate center
        """
        from Npp import editor
        
        # undo
        editor.undo()
        
        # find location after undo
        pc = editor.getCurrentPos()
        c = editor.lineFromPosition(pc)
        editor.gotoLine(1)
        editor.gotoLine(c)
        editor.setCurrentPos(pc)
        
        # try to center it
        # this is counting >1 for a wrapped line, whereas the "Line" commands are logical line, but close enough
        h = editor.linesOnScreen()
        f = editor.getFirstVisibleLine()
        s = int(c - h/2)
        
        #console.write(f"h={h}, f={f}, c={c}, s={s}\n")
        editor.lineScroll(0, s)
        
        del(pc)
        del(c)
        del(h)
        del(f)
        del(s)
        

        redo_and_scroll.py:

        # encoding=utf-8
        """in response to https://community.notepad-plus-plus.org/topic/27122/
        
        This does the REDO then tries to scroll to approximate center
        """
        from Npp import editor
        
        # redo
        editor.redo()
        
        # find location after undo
        pc = editor.getCurrentPos()
        c = editor.lineFromPosition(pc)
        editor.gotoLine(1)
        editor.gotoLine(c)
        editor.setCurrentPos(pc)
        
        # try to center it
        # this is counting >1 for a wrapped line, whereas the "Line" commands are logical line, but close enough
        h = editor.linesOnScreen()
        f = editor.getFirstVisibleLine()
        s = int(c - h/2)
        
        #console.write(f"h={h}, f={f}, c={c}, s={s}\n")
        editor.lineScroll(0, s)
        
        del(pc)
        del(c)
        del(h)
        del(f)
        del(s)
        
        1 Reply Last reply Reply Quote 0
        • PeterJonesP PeterJones referenced this topic on
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors