Get undo to scroll to context
-
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?
-
@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.
- Install PythonScript 3.0.22 or later per the PythonScript 3.0.x instructions in our PythonScript FAQ
- Create and populate the new script
undo_and_scroll.pyusing the source below and the instructions for “create” and “populate” in the FAQ - Create and populate the new script
redo_and_scroll.pyusing the second source below and the same instructions - Verify them using Plugins > Python Script > Scripts >
undo_and_scrollorredo_and_scroll - Once they are working, if you want, you can follow the FAQ instructions to create a shortcut for each (you could replace the
Ctrl+ZandCtrl+Y– but you’d have to use the shortcut mapper on theScintilla commandspage 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) -
P PeterJones referenced this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login