From dc4cef62cd7114c9a96f40005aeb983a7ea0c701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Ni=C3=9Fl?= Date: Sun, 31 Jan 2016 14:23:34 +1100 Subject: 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. --- src/Editor.cxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/Editor.cxx') 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) { -- cgit v1.2.3