Automatically scrolling to caret
-
Is there a way to set a shortut that automatically scrolls the current file so that the line displayed at the top is the one where the caret is currently placed? I know that SCI_SCROLLCARET can be configured in the shortcut mapper, but it only works if the caret is currently out of view.
Thanks in advance :)
-
I don’t know about other methods, but I tried the following bit of script code using the PythonScript plugin, and it seems to work to do the desired thing:
editor.setFirstVisibleLine(editor.lineFromPosition(editor.getCurrentPos()))
-
@alan-kilborn
Thanks a lot for your reply! I tried what you suggested and it does indeed work under normal circumstances. However, when word wrap is enabled and I’m working with wrapped lines, the behavior of the script becomes rather unpredictable (to me, at least): under those conditions, it doesn’t actually scroll to the caret, but rather to a position a few lines before it.
I suppose this is due to the fact that the actual position of the lines is altered by word wrap, but I have no idea how to solve the problem. Do you? -
@tamarindo94 said in Automatically scrolling to caret:
However, when word wrap is enabled and I’m working with wrapped lines, the behavior of the script becomes rather unpredictable (to me, at least): under those conditions, it doesn’t actually scroll to the caret, but rather to a position a few lines before it.
I suppose this is due to the fact that the actual position of the lines is altered by word wrap, but I have no idea how to solve the problem. Do you?Maybe you need to include “Scintilla ensure visible commands”?
Cheers.
-
I did some experiments with Word Wrap enabled and confirmed the finding of @Tamarindo94. In every case in my experiments, the line of the caret remained visible in the viewport, just not necessarily as the first line of the viewport, as one would be led to believe from the setFirstVisibleLine function call.
Unfortunately, I don’t really see a way to fix the bad behavior. There are other problems/complaints with functionality of Notepad++ with Word Wrap enabled, maybe this is just one more. :-(
-
Actually, this seems to do it:
editor.setFirstVisibleLine(editor.visibleFromDocLine(editor.lineFromPosition(editor.getCurrentPos())))