diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index fbc457313..7ff00e6c2 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1549,6 +1549,11 @@ BOOL Notepad_plus::notify(SCNotification *notification) _isDocModifing = true; ::InvalidateRect(_pEditView->getHSelf(), NULL, TRUE); } + if (notification->modificationType & SC_MOD_CHANGEFOLD) + { + _pEditView->foldChanged(notification->line, + notification->foldLevelNow, notification->foldLevelPrev); + } } break; @@ -1986,7 +1991,19 @@ BOOL Notepad_plus::notify(SCNotification *notification) _isHotspotDblClicked = true; _pEditView->execute(SCI_SETCHARSDEFAULT); break; - } + } + + case SCN_NEEDSHOWN : + { + int begin = _pEditView->execute(SCI_LINEFROMPOSITION, notification->position); + int end = _pEditView->execute(SCI_LINEFROMPOSITION, notification->position + notification->length); + int firstLine = begin < end ? begin : end; + int lastLine = begin > end ? begin : end; + for (int line = firstLine; line <= lastLine; line++) { + _pEditView->execute(SCI_ENSUREVISIBLE, line, 0); + } + break; + } default : break; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 4e4a77cf5..83082c61b 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -660,9 +660,12 @@ private: void checkLangsMenu(int id) const ; void setLanguage(int id, LangType langType) { - _pEditView->setCurrentDocType(langType); - setLangStatus(langType); - checkLangsMenu(id); + if (_pEditView->setCurrentDocType(langType)) + { + _pEditView->foldAll(fold_uncollapse); + setLangStatus(langType); + checkLangsMenu(id); + } }; int getToolBarState() const { diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 91e9d960d..20f61aae5 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -1723,4 +1723,35 @@ void ScintillaEditView::recalcHorizontalScrollbar() int currentLength = execute(SCI_GETSCROLLWIDTH); //Get current scrollbar size if (currentLength != maxPixel) //And if it is not the same execute(SCI_SETSCROLLWIDTH, maxPixel); //update it -} \ No newline at end of file +} + +void ScintillaEditView::foldChanged(int line, int levelNow, int levelPrev) +{ + if (levelNow & SC_FOLDLEVELHEADERFLAG) + { + if (!(levelPrev & SC_FOLDLEVELHEADERFLAG)) + { + // Adding a fold point. + execute(SCI_SETFOLDEXPANDED, line, 1); + expand(line, true, false, 0, levelPrev); + } + } + else if (levelPrev & SC_FOLDLEVELHEADERFLAG) + { + if (!execute(SCI_GETFOLDEXPANDED, line)) + { + // Removing the fold from one that has been contracted so should expand + // otherwise lines are left invisible with no way to make them visible + execute(SCI_SETFOLDEXPANDED, line, 1); + expand(line, true, false, 0, levelPrev); + } + } + else if (!(levelNow & SC_FOLDLEVELWHITEFLAG) && + ((levelPrev & SC_FOLDLEVELNUMBERMASK) > (levelNow & SC_FOLDLEVELNUMBERMASK))) + { + // See if should still be hidden + int parentLine = execute(SCI_GETFOLDPARENT, line); + if ((parentLine < 0) || (execute(SCI_GETFOLDEXPANDED, parentLine) && execute(SCI_GETLINEVISIBLE, parentLine))) + execute(SCI_SHOWLINES, line, line); + } +} diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 65c52052b..43b08b8c4 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -151,14 +151,15 @@ public: void defineDocType(LangType typeDoc); - void setCurrentDocType(LangType typeDoc) { + bool setCurrentDocType(LangType typeDoc) { if ((_buffers[_currentIndex]._lang == typeDoc) && (typeDoc != L_USER)) - return; + return false; if (typeDoc == L_USER) _buffers[_currentIndex]._userLangExt[0] = '\0'; _buffers[_currentIndex]._lang = typeDoc; defineDocType(typeDoc); + return true; }; void setCurrentDocUserType(const char *userLangName) { @@ -591,7 +592,9 @@ public: void columnReplace(const ColumnModeInfo & cmi, const char ch); void columnReplace(ColumnModeInfo & cmi, int initial, int incr, unsigned char format); - void ScintillaEditView::recalcHorizontalScrollbar(); + void recalcHorizontalScrollbar(); + void foldChanged(int line, int levelNow, int levelPrev); + protected: static HINSTANCE _hLib; static int _refCount;