[NEW_FEATURE] Wrap position restore while switching back document.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@123 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-02-04 22:44:01 +00:00
parent 4b0926a0d2
commit e240ac8c6d
4 changed files with 51 additions and 31 deletions

View File

@ -363,8 +363,10 @@ bool Notepad_plus::loadSession(Session & session)
if (session._activeSubIndex < session.nbSubFiles())
_subDocTab.activate(session._activeSubIndex);
if (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW)
if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW))
switchEditViewTo(session._activeView);
else
switchEditViewTo(MAIN_VIEW);
return allSessionFilesLoaded;
}
@ -1170,7 +1172,7 @@ bool Notepad_plus::fileSaveAs()
_pEditView->setCurrentDocReadOnly(false);
_pDocTab->updateCurrentTabItem(PathFindFileName(pfn));
setTitleWith(pfn);
//setLangStatus(_pEditView->getCurrentDocType());
setLangStatus(_pEditView->getCurrentDocType());
checkLangsMenu(-1);
return true;
}
@ -1935,15 +1937,15 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_macro.push_back(recordedMacroStep(notification->message, notification->wParam, notification->lParam));
break;
/*
case SCN_STYLENEEDED:
{
}
break;
*/
case SCN_PAINTED:
{
//Wrapping messes up visible lines, restore after SCN_PAINTED as doc. says
if (_pEditView->needRestoreFromWrap())
{
_pEditView->restoreFromWrap();
}
if (_syncInfo.doSync())
doSynScorll(HWND(notification->nmhdr.hwndFrom));
@ -7329,6 +7331,9 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_MAKECURRENTBUFFERDIRTY :
{
_pEditView->setCurrentDocState(true);
_pDocTab->updateCurrentTabItem();
checkDocState();
synchronise();
return TRUE;
}
@ -7546,7 +7551,7 @@ void Notepad_plus::fullScreenToggle()
::ShowWindow(_hSelf, SW_HIDE);
::SetMenu(_hSelf, _mainMenuHandle);
::SetWindowLongPtr( _hSelf, GWL_STYLE, _prevStyles);
::SetWindowPos(_hSelf, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW);
::SetWindowPos(_hSelf, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER);
//Restore the toolbar to its previous state
int cmdToSend = 0;

View File

@ -93,6 +93,7 @@ struct HeaderLineState {
struct Position
{
int _firstVisibleLine;
int _wrapOffset;
int _startPos;
int _endPos;
int _xOffset;

View File

@ -143,7 +143,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
case WM_MOUSEHWHEEL :
case WM_MOUSEWHEEL :
//case WM_RBUTTONDOWN :
{
if (LOWORD(wParam) & MK_RBUTTON)
{
@ -158,12 +157,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
break;
}
/*
{
::CallWindowProc(_scintillaDefaultProc, hwnd, WM_HSCROLL, ((short)HIWORD(wParam))>0?SB_LINERIGHT:SB_LINELEFT, NULL);
break;
}
*/
case WM_VSCROLL :
{
if (LOWORD(wParam) == SB_ENDSCROLL)
@ -862,21 +855,16 @@ int ScintillaEditView::findDocIndexByName(const char *fn) const
void ScintillaEditView::saveCurrentPos()
{
//Save data so, that the current topline becomes visible again after restoring.
int displayedLine = static_cast<int>(execute(SCI_GETFIRSTVISIBLELINE));
int docLine = execute(SCI_DOCLINEFROMVISIBLE, displayedLine);
int docLine = execute(SCI_DOCLINEFROMVISIBLE, displayedLine); //linenumber of the line displayed in the top
int offset = displayedLine - execute(SCI_VISIBLEFROMDOCLINE, docLine); //use this to calc offset of wrap. If no wrap this should be zero
int nbInvisibleLine = 0;
//Calculate nb of invisible line
for (int i = 0 ; i < docLine ; i++)
if (execute(SCI_GETLINEVISIBLE, i) == FALSE)
nbInvisibleLine++;
Buffer & buf = _buffers[_currentIndex];
Buffer & buf = _buffers[_currentIndex];
// the correct visible line number
buf._pos._firstVisibleLine = docLine - nbInvisibleLine;
buf._pos._firstVisibleLine = docLine;//docLine - nbInvisibleLine;
buf._pos._wrapOffset = offset;
buf._pos._startPos = static_cast<int>(execute(SCI_GETSELECTIONSTART));
buf._pos._endPos = static_cast<int>(execute(SCI_GETSELECTIONEND));
buf._pos._xOffset = static_cast<int>(execute(SCI_GETXOFFSET));
@ -885,11 +873,17 @@ void ScintillaEditView::saveCurrentPos()
void ScintillaEditView::restoreCurrentPos(const Position & prevPos)
{
int scroll2Top = 0 - (int(execute(SCI_GETLINECOUNT)) + 1);
scroll(0, scroll2Top);
_wrapRestoreNeeded = isWrap();
execute(SCI_GOTOPOS, 0); //make sure first line visible by setting caret there, will scroll to top of document
Buffer & buf = _buffers[_currentIndex];
scroll(0, buf._pos._firstVisibleLine);
if (!_wrapRestoreNeeded)
{
int lineToShow = execute(SCI_VISIBLEFROMDOCLINE, buf._pos._firstVisibleLine);
scroll(0, lineToShow);
}
if (buf._pos._selMode == SC_SEL_RECTANGLE)
{
execute(SCI_SETSELECTIONMODE, buf._pos._selMode);
@ -899,6 +893,19 @@ void ScintillaEditView::restoreCurrentPos(const Position & prevPos)
execute(SCI_SETXOFFSET, buf._pos._xOffset);
}
void ScintillaEditView::restoreFromWrap()
{
Buffer & buf = _buffers[_currentIndex];
int lineToShow = execute(SCI_VISIBLEFROMDOCLINE, buf._pos._firstVisibleLine);
//Scroll to the line that corresponds to the stored docline and then some more for the wrapping offset.
//Should work with folding too.
scroll(0, lineToShow + buf._pos._wrapOffset);
_wrapRestoreNeeded = false;
}
//! \brief this method activates the doc and the corresponding sub tab
//! \brief return the index of previeus current doc
char * ScintillaEditView::activateDocAt(int index)

View File

@ -234,6 +234,11 @@ public:
void saveCurrentPos();
void restoreCurrentPos(const Position & prevPos);
bool needRestoreFromWrap() {
return _wrapRestoreNeeded;
}
void restoreFromWrap();
Buffer & getBufferAt(size_t index) {
if (index >= _buffers.size())
@ -639,6 +644,8 @@ protected:
int _maxNbDigit; // For Line Number Marge
bool _wrapRestoreNeeded;
void setStyle(int styleID, COLORREF fgColor, COLORREF bgColor = -1, const char *fontName = NULL, int fontStyle = -1, int fontSize = 0);
void setSpecialStyle(int styleID, COLORREF fgColor, COLORREF bgColor = -1, const char *fontName = NULL, int fontStyle = -1, int fontSize = 0);
void setCppLexer(LangType type);