From 7363f3ce9a5068c9c23f948a7e11541f4f9e50d0 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sun, 18 Jan 2004 07:15:12 +0000 Subject: Patch from Bruce Dodson to ensure correct folding. When toggling fold on line that is not a fold header line, toggle the previous fold header line. --- src/Editor.cxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Editor.cxx b/src/Editor.cxx index f02ce2b6a..f9d20aa47 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5276,16 +5276,34 @@ void Editor::Expand(int &line, bool doExpand) { } void Editor::ToggleContraction(int line) { - if (pdoc->GetLevel(line) & SC_FOLDLEVELHEADERFLAG) { + if (line >= 0) { + if ((pdoc->GetLevel(line) & SC_FOLDLEVELHEADERFLAG) == 0) { + line = pdoc->GetFoldParent(line); + if (line < 0) + return; + } + if (cs.GetExpanded(line)) { int lineMaxSubord = pdoc->GetLastChild(line); cs.SetExpanded(line, 0); if (lineMaxSubord > line) { cs.SetVisible(line + 1, lineMaxSubord, false); + + int lineCurrent = pdoc->LineFromPosition(currentPos); + if (lineCurrent > line && lineCurrent <= lineMaxSubord) { + // This does not re-expand the fold + EnsureCaretVisible(); + } + SetScrollBars(); Redraw(); } + } else { + if (!(cs.GetVisible(line))) { + EnsureLineVisible(line, false); + GoToLine(line); + } cs.SetExpanded(line, 1); Expand(line, true); SetScrollBars(); -- cgit v1.2.3