To reproduce (Win7 Home SP2):
1) Open the attached file in SciTE or Notepad++. (There is presumably nothing special about it other than the fact that it's one really long line).
2) Make sure word wrap is on.
4) Press Ctrl+End to go to the end of the file.
5) Press Ctrl+N to open a new file.
6) Press Ctrl+Tab to go back to the attached file.
The scroll bar is at the "top", and the caret position is not visible. The caret is at the correct place, so it's just the scrolling which is off.
I was trying to fix this in Notepad++ but noticed that it happened in SciTE as well, so I think it's a problem with Scintilla.
I found this bug report but I couldn't get to work even after modifying Notepad++:
https://sourceforge.net/tracker/index.php?func=detail&aid=1207143&group_id=2439&atid=102439
There is no step 3 btw, that's a mistake ;)
In SciTE, the scroll position when switching tabs is set by SciTE (SciTEBase::DisplayAround), not Scintilla. I won't be working on this myself.
Yes, it's application's responsibility to set the scroll position. The thing is that it doesn't seem work. Even with a SCI_SCROLLCARET at the very of the Notepad++ equivalent of SciTEBase::DisplayAround, the result is the same: the caret position is correct (bottom of doc), but the scroll position is wrong (start of doc).
SciTE does not use SCI_SCROLLCARET when switching tabs.
Line wrapping is a background activity that takes time. At the point that SCI_SCROLLCARET is called, it is likely that the wrapping has not yet been done.
Is there some way for the application to block until line wrapping has been done, so that SCI_SCROLLCARET or SCI_GOTOPOS (or similar) will take effect?
It's possible to get it working by sending SCI_SCROLLCARET after SCN_PAINTED.
While this will work much of the time, there are circumstances in which it may not for large files. The initial scroll position will have to be far enough down for the wrapping to have been done for the line containing the caret. To be safe, you should check that the line containing the caret is on-screen inside SCN_PAINTED.