diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 1fb06aa0..15f026e1 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -276,7 +276,7 @@ void Buffer::setHeaderLineState(const std::vector & folds, Scin } } -std::vector & Buffer::getHeaderLineState(ScintillaEditView * identifier) { +const std::vector & Buffer::getHeaderLineState(const ScintillaEditView * identifier) const { int index = indexOfReference(identifier); return _foldStates.at(index); } @@ -295,7 +295,7 @@ Lang * Buffer::getCurrentLang() const { return NULL; }; -int Buffer::indexOfReference(ScintillaEditView * identifier) const { +int Buffer::indexOfReference(const ScintillaEditView * identifier) const { int size = (int)_referees.size(); for(int i = 0; i < size; i++) { if (_referees[i] == identifier) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index eb3ef2a7..bec583d3 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -246,7 +246,7 @@ public : Position & getPosition(ScintillaEditView * identifier); void setHeaderLineState(const std::vector & folds, ScintillaEditView * identifier); - std::vector & getHeaderLineState(ScintillaEditView * identifier); + const std::vector & getHeaderLineState(const ScintillaEditView * identifier) const; bool isUserDefineLangExt() const { return (_userLangExt[0] != '\0'); @@ -355,7 +355,7 @@ private : void updateTimeStamp(); - int indexOfReference(ScintillaEditView * identifier) const; + int indexOfReference(const ScintillaEditView * identifier) const; void setStatus(DocFileStatus status) { _currentStatus = status; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 39aaec62..65224274 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -1445,19 +1445,7 @@ void ScintillaEditView::activateBuffer(BufferID buffer) saveCurrentPos(); // get foldStateInfo of current doc - std::vector lineStateVector; - - int maxLine = execute(SCI_GETLINECOUNT); - - for (int line = 0; line < maxLine; line++) - { - int level = execute(SCI_GETFOLDLEVEL, line); - if (level & SC_FOLDLEVELHEADERFLAG) - { - bool expanded = (execute(SCI_GETFOLDEXPANDED, line) != 0); - lineStateVector.push_back(HeaderLineState(line, expanded)); - } - } + std::vector lineStateVector = getCurrentFoldStates(); // put the state into the future ex buffer _currentBuffer->setHeaderLineState(lineStateVector, this); @@ -1479,18 +1467,8 @@ void ScintillaEditView::activateBuffer(BufferID buffer) } // restore the collapsed info - std::vector & lineStateVectorNew = newBuf->getHeaderLineState(this); - int nbLineState = lineStateVectorNew.size(); - for (int i = 0 ; i < nbLineState ; i++) - { - HeaderLineState & hls = lineStateVectorNew.at(i); - bool expanded = isFolded(hls._headerLineNumber); - // set line to state folded - if (hls._isExpanded != expanded) - { - fold(hls._headerLineNumber, !expanded); - } - } + const std::vector & lineStateVectorNew = newBuf->getHeaderLineState(this); + syncFoldStateWith(lineStateVectorNew); restoreCurrentPos(); @@ -1506,6 +1484,38 @@ void ScintillaEditView::activateBuffer(BufferID buffer) return; //all done } +std::vector ScintillaEditView::getCurrentFoldStates() +{ + std::vector lineStateVector; + int maxLine = execute(SCI_GETLINECOUNT); + + for (int line = 0; line < maxLine; line++) + { + int level = execute(SCI_GETFOLDLEVEL, line); + if (level & SC_FOLDLEVELHEADERFLAG) + { + bool expanded = (execute(SCI_GETFOLDEXPANDED, line) != 0); + lineStateVector.push_back(HeaderLineState(line, expanded)); + } + } + return lineStateVector; +} + +void ScintillaEditView::syncFoldStateWith(const std::vector & lineStateVectorNew) +{ + int nbLineState = lineStateVectorNew.size(); + for (int i = 0 ; i < nbLineState ; i++) + { + const HeaderLineState & hls = lineStateVectorNew.at(i); + bool expanded = isFolded(hls._headerLineNumber); + // set line to state folded + if (hls._isExpanded != expanded) + { + fold(hls._headerLineNumber, !expanded); + } + } +} + void ScintillaEditView::bufferUpdated(Buffer * buffer, int mask) { //actually only care about language and lexing etc diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 74a4fbdf..291e60a8 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -231,6 +231,9 @@ public: void activateBuffer(BufferID buffer); + std::vector getCurrentFoldStates(); + void syncFoldStateWith(const std::vector & lineStateVectorNew); + void getText(char *dest, int start, int end) const; void getGenericText(TCHAR *dest, int start, int end) const; void getGenericText(TCHAR *dest, int start, int end, int *mstart, int *mend) const; diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp index 22d9af3e..112962f0 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp @@ -29,7 +29,16 @@ void DocumentMap::reloadMap() Document currentDoc = (*_ppEditView)->execute(SCI_GETDOCPOINTER); ::SendMessage(_pScintillaEditView->getHSelf(), SCI_SETDOCPOINTER, 0, (LPARAM)currentDoc); //_pScintillaEditView->wrap((*_ppEditView)->isWrap()); + + // sync with the current document + // Lexing + _pScintillaEditView->defineDocType((*_ppEditView)->getCurrentBuffer()->getLangType()); + + // folding + _pScintillaEditView->syncFoldStateWith((*_ppEditView)->getCurrentFoldStates()); + scrollMap(); + } } @@ -131,7 +140,6 @@ BOOL CALLBACK DocumentMap::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara reloadMap(); _pScintillaEditView->showIndentGuideLine(false); - _pScintillaEditView->defineDocType((*_ppEditView)->getCurrentBuffer()->getLangType()); _pScintillaEditView->showMargin(0, false); _pScintillaEditView->showMargin(1, false);