From a91e4af5c5fbbe464093e24ae39f980b56598847 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Sat, 30 Jul 2022 09:00:32 +1000 Subject: Bug [#2340] Add option to contract every level for SCI_FOLDALL called SC_FOLDACTION_CONTRACT_EVERY_LEVEL. Avoid processing lines multiple times. --- doc/ScintillaDoc.html | 6 ++++++ doc/ScintillaHistory.html | 5 +++++ include/Scintilla.h | 1 + include/Scintilla.iface | 1 + include/ScintillaTypes.h | 1 + src/Editor.cxx | 29 +++++++++++++++++++---------- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index bcbc88152..dfa138b29 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -7591,6 +7591,12 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ Toggle between contracted and expanded. + + SC_FOLDACTION_CONTRACT_EVERY_LEVEL + 4 + Used for SCI_FOLDALL only, can be combined with SC_FOLDACTION_CONTRACT or SC_FOLDACTION_TOGGLE to contract all levels instead of only top-level. + + diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 08c00bf86..1188fbc00 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -605,6 +605,11 @@ Feature #1441.
  • + Add SC_FOLDACTION_CONTRACT_EVERY_LEVEL option to contract every level for + SCI_FOLDALL. + Bug #2340. +
  • +
  • Enable multiline regex for gcc and clang when REGEX_MULTILINE defined. This requires gcc 11.3 or clang 14. Bug #2338. diff --git a/include/Scintilla.h b/include/Scintilla.h index 0dacb3c1b..5781674e3 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -598,6 +598,7 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SC_FOLDACTION_CONTRACT 0 #define SC_FOLDACTION_EXPAND 1 #define SC_FOLDACTION_TOGGLE 2 +#define SC_FOLDACTION_CONTRACT_EVERY_LEVEL 4 #define SCI_FOLDLINE 2237 #define SCI_FOLDCHILDREN 2238 #define SCI_EXPANDCHILDREN 2239 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 646c01a8a..bd6cb76de 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1563,6 +1563,7 @@ enu FoldAction=SC_FOLDACTION_ val SC_FOLDACTION_CONTRACT=0 val SC_FOLDACTION_EXPAND=1 val SC_FOLDACTION_TOGGLE=2 +val SC_FOLDACTION_CONTRACT_EVERY_LEVEL=4 # Expand or contract a fold header. fun void FoldLine=2237(line line, FoldAction action) diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index ba19b1253..343dec749 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -302,6 +302,7 @@ enum class FoldAction { Contract = 0, Expand = 1, Toggle = 2, + ContractEveryLevel = 4, }; enum class AutomaticFold { diff --git a/src/Editor.cxx b/src/Editor.cxx index 08ee3fc6a..f7d6a784b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5582,15 +5582,18 @@ void Editor::EnsureLineVisible(Sci::Line lineDoc, bool enforcePolicy) { void Editor::FoldAll(FoldAction action) { const Sci::Line maxLine = pdoc->LinesTotal(); + const bool contractAll = FlagSet(action, FoldAction::ContractEveryLevel); + action = static_cast(static_cast(action) & ~static_cast(FoldAction::ContractEveryLevel)); bool expanding = action == FoldAction::Expand; if (!expanding) { pdoc->EnsureStyledTo(pdoc->Length()); } + Sci::Line line = 0; if (action == FoldAction::Toggle) { // Discover current state - for (Sci::Line lineSeek = 0; lineSeek < maxLine; lineSeek++) { - if (LevelIsHeader(pdoc->GetFoldLevel(lineSeek))) { - expanding = !pcs->GetExpanded(lineSeek); + for (; line < maxLine; line++) { + if (LevelIsHeader(pdoc->GetFoldLevel(line))) { + expanding = !pcs->GetExpanded(line); break; } } @@ -5599,14 +5602,20 @@ void Editor::FoldAll(FoldAction action) { pcs->SetVisible(0, maxLine-1, true); pcs->ExpandAll(); } else { - for (Sci::Line line = 0; line < maxLine; line++) { + for (; line < maxLine; line++) { const FoldLevel level = pdoc->GetFoldLevel(line); - if (LevelIsHeader(level) && - (FoldLevel::Base == LevelNumberPart(level))) { - SetFoldExpanded(line, false); - const Sci::Line lineMaxSubord = pdoc->GetLastChild(line); - if (lineMaxSubord > line) { - pcs->SetVisible(line + 1, lineMaxSubord, false); + if (LevelIsHeader(level)) { + if (FoldLevel::Base == LevelNumberPart(level)) { + SetFoldExpanded(line, false); + const Sci::Line lineMaxSubord = pdoc->GetLastChild(line); + if (lineMaxSubord > line) { + pcs->SetVisible(line + 1, lineMaxSubord, false); + if (!contractAll) { + line = lineMaxSubord; + } + } + } else if (contractAll) { + SetFoldExpanded(line, false); } } } -- cgit v1.2.3