aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorZufu Liu <unknown>2022-07-30 09:00:32 +1000
committerZufu Liu <unknown>2022-07-30 09:00:32 +1000
commita91e4af5c5fbbe464093e24ae39f980b56598847 (patch)
treeac6869d1ec21269c23954a931a334a002800c934 /src
parent987598c6d853eac0a99bbf97f4fe847874652ed3 (diff)
downloadscintilla-mirror-a91e4af5c5fbbe464093e24ae39f980b56598847.tar.gz
Bug [#2340] Add option to contract every level for SCI_FOLDALL called
SC_FOLDACTION_CONTRACT_EVERY_LEVEL. Avoid processing lines multiple times.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx29
1 files changed, 19 insertions, 10 deletions
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<FoldAction>(static_cast<int>(action) & ~static_cast<int>(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);
}
}
}