diff options
author | Markus Nißl <devnull@localhost> | 2016-01-31 14:23:34 +1100 |
---|---|---|
committer | Markus Nißl <devnull@localhost> | 2016-01-31 14:23:34 +1100 |
commit | a9880d7d2bba46107f7e700b707c06ea82124269 (patch) | |
tree | 9237bfe3acd56cbc14da0ad786023ffb2263a30d | |
parent | 36eb6b04ed060d7600f6eae682bc4a97d82089ac (diff) | |
download | scintilla-mirror-a9880d7d2bba46107f7e700b707c06ea82124269.tar.gz |
Bug [#1799]. Folds unfolded when two fold regions are merged by either deleting
an intervening line or changing its fold level by adding characters.
Add LevelNumber function to simplify expressions implmenting folding.
-rw-r--r-- | doc/ScintillaHistory.html | 6 | ||||
-rw-r--r-- | src/Document.h | 4 | ||||
-rw-r--r-- | src/Editor.cxx | 17 |
3 files changed, 27 insertions, 0 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index d33d0f2b7..c70134661 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -503,6 +503,12 @@ the line end characters. </li> <li> + Folds unfolded when two fold regions are merged by either deleting an intervening line + or changing its fold level by adding characters. + This was fixed both in Scintilla and in SciTE's equivalent code. + <a href="http://sourceforge.net/p/scintilla/bugs/1799/">Bug #1799</a>.<br /> + </li> + <li> For Qt, release builds have assertions turned off. </li> <li> diff --git a/src/Document.h b/src/Document.h index cc3873f59..d82aa46b5 100644 --- a/src/Document.h +++ b/src/Document.h @@ -171,6 +171,10 @@ public: class Document; +inline int LevelNumber(int level) { + return level & SC_FOLDLEVELNUMBERMASK; +} + class LexInterface { protected: Document *pdoc; diff --git a/src/Editor.cxx b/src/Editor.cxx index 08248a3d9..d9bc37694 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5422,12 +5422,20 @@ void Editor::FoldChanged(int line, int levelNow, int levelPrev) { FoldExpand(line, SC_FOLDACTION_EXPAND, levelPrev); } } else if (levelPrev & SC_FOLDLEVELHEADERFLAG) { + const int prevLine = line - 1; + const int prevLineLevel = pdoc->GetLevel(prevLine); + + // Combining two blocks where the first block is collapsed (e.g. by deleting the line(s) which separate(s) the two blocks) + if ((LevelNumber(prevLineLevel) == LevelNumber(levelNow)) && !cs.GetVisible(prevLine)) + FoldLine(pdoc->GetFoldParent(prevLine), SC_FOLDACTION_EXPAND); + if (!cs.GetExpanded(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 if (cs.SetExpanded(line, true)) { RedrawSelMargin(); } + // Combining two blocks where the second one is collapsed (e.g. by adding characters in the line which separates the two blocks) FoldExpand(line, SC_FOLDACTION_EXPAND, levelPrev); } } @@ -5443,6 +5451,15 @@ void Editor::FoldChanged(int line, int levelNow, int levelPrev) { } } } + + // Combining two blocks where the first one is collapsed (e.g. by adding characters in the line which separates the two blocks) + if (!(levelNow & SC_FOLDLEVELWHITEFLAG) && (LevelNumber(levelPrev) < LevelNumber(levelNow))) { + if (cs.HiddenLines()) { + const int parentLine = pdoc->GetFoldParent(line); + if (!cs.GetExpanded(parentLine) && cs.GetExpanded(line)) + FoldLine(parentLine, SC_FOLDACTION_EXPAND); + } + } } void Editor::NeedShown(int pos, int len) { |