Menu command for ensuring current position is visible
-
I almost never used code folding in Notepad++, so it’s only today that I noticed that there doesn’t really seem to be an easy way to recursively unfold everything above the current caret position if the caret is not directly below the uppermost folded level. This came up because PeterJones made an issue in my JsonTools plugin regarding code folding. Below I will describe a couple of existing ways to do this, and argue that it might be beneficial to add a new feature.
And yes, I’m aware that feature requests have to be submitted at the GitHub repo, but I just wanted to post here initially to see what others thought.
For example, suppose I have this document:
{ "foo": [ { "ONE": [ 1234 ] }, { "TWO": [ null ] } ] }and suppose that my caret is currently at position 70 inside the number
1234, four fold levels deep.Now suppose that use
View->Fold Level->3to fold the document so it looks like this:

Now my caret is hidden, and I want to unfold just enough to make the caret visible, so that the document would look like this:

Since the caret is currently under fold level 4 but the uppermost fold level above it is level 2,
View->Unfold Current Leveldoesn’t do what I want. The folding command that would come closest to achieving my goal would be View->Unfold Level->3`, but (a) that would unfold everything at that fold level (not just directly above the caret), and (b) I would need to know to unfold level 3, as opposed to some other level.In general, the easiest way to do this is by typing any character and then reverting that change, but this very simple solution does not work if the current document is read-only.
It is possible to do this using only builtin menu commands and dialogs:
- Open a dialog with
Search->Go to... - Click the
Offsetoption. - Enter the current offset indicated in the dialog.
- Hit
Go
While I am generally in favor of not adding a new feature to do X when X can already be done somewhat easily with a combination of existing features, it does seem to me like the most general current workaround is a little bit hard to discover, especially since the desired functionality involves manipulating folding (generally in the
Viewmenu) but the workaround uses theSearchmenu instead.In any case, it seems that the
Search->Go to...dialog uses a Scintilla command calledSCI_ENSUREVISIBLEto make the current line visible without moving the caret (full implementation here). It is also quite easy to script this using PythonScript with the below one-liner:
editor.ensureVisible(editor.lineFromPosition(editor.getCurrentPos()))So basically I’m thinking that it might be helpful to have a new command under the
Viewmenu calledMake current position visibleor something like that. - Open a dialog with