diff options
author | Zufu Liu <unknown> | 2022-07-24 10:00:06 +1000 |
---|---|---|
committer | Zufu Liu <unknown> | 2022-07-24 10:00:06 +1000 |
commit | 2a922d679ec36743287191fbd9f67a6fef9f7f1b (patch) | |
tree | b5743e169339ff691913b9fd0a5d59455db73498 | |
parent | 46e54d394dfd76a0d3055850ce8e6f394dfe2ba7 (diff) | |
download | scintilla-mirror-2a922d679ec36743287191fbd9f67a6fef9f7f1b.tar.gz |
Bug [#2340] Simplify expand all folds. Speed up expand line a little.
-rw-r--r-- | src/ContractionState.cxx | 26 | ||||
-rw-r--r-- | src/ContractionState.h | 1 | ||||
-rw-r--r-- | src/Editor.cxx | 13 | ||||
-rw-r--r-- | test/unit/testContractionState.cxx | 22 |
4 files changed, 51 insertions, 11 deletions
diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index 8b4babb2e..eacda2ce2 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -80,6 +80,7 @@ public: bool GetExpanded(Sci::Line lineDoc) const noexcept override; bool SetExpanded(Sci::Line lineDoc, bool isExpanded) override; + bool ExpandAll() override; Sci::Line ContractedNext(Sci::Line lineDocStart) const noexcept override; int GetHeight(Sci::Line lineDoc) const noexcept override; @@ -248,23 +249,26 @@ bool ContractionState<LINE>::SetVisible(Sci::Line lineDocStart, Sci::Line lineDo return false; } else { EnsureData(); - Sci::Line delta = 0; Check(); if ((lineDocStart <= lineDocEnd) && (lineDocStart >= 0) && (lineDocEnd < LinesInDoc())) { + bool changed = false; for (Sci::Line line = lineDocStart; line <= lineDocEnd; line++) { if (GetVisible(line) != isVisible) { + changed = true; const int heightLine = heights->ValueAt(static_cast<LINE>(line)); const int difference = isVisible ? heightLine : -heightLine; - visible->SetValueAt(static_cast<LINE>(line), isVisible ? 1 : 0); displayLines->InsertText(static_cast<LINE>(line), difference); - delta += difference; } } + if (changed) { + visible->FillRange(static_cast<LINE>(lineDocStart), isVisible ? 1 : 0, + static_cast<LINE>(lineDocEnd - lineDocStart) + 1); + } + Check(); + return changed; } else { return false; } - Check(); - return delta != 0; } } @@ -326,6 +330,18 @@ bool ContractionState<LINE>::SetExpanded(Sci::Line lineDoc, bool isExpanded) { } template <typename LINE> +bool ContractionState<LINE>::ExpandAll() { + if (OneToOne()) { + return false; + } else { + const LINE lines = expanded->Length(); + const bool changed = expanded->FillRange(0, 1, lines).changed; + Check(); + return changed; + } +} + +template <typename LINE> Sci::Line ContractionState<LINE>::ContractedNext(Sci::Line lineDocStart) const noexcept { if (OneToOne()) { return -1; diff --git a/src/ContractionState.h b/src/ContractionState.h index 55c390c55..ae753f8d1 100644 --- a/src/ContractionState.h +++ b/src/ContractionState.h @@ -36,6 +36,7 @@ public: virtual bool GetExpanded(Sci::Line lineDoc) const noexcept=0; virtual bool SetExpanded(Sci::Line lineDoc, bool isExpanded)=0; + virtual bool ExpandAll()=0; virtual Sci::Line ContractedNext(Sci::Line lineDocStart) const noexcept =0; virtual int GetHeight(Sci::Line lineDoc) const noexcept=0; diff --git a/src/Editor.cxx b/src/Editor.cxx index 5b0486be0..a4e2cc732 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5414,18 +5414,23 @@ void Editor::SetEOLAnnotationVisible(EOLAnnotationVisible visible) { Sci::Line Editor::ExpandLine(Sci::Line line) { const Sci::Line lineMaxSubord = pdoc->GetLastChild(line); line++; + Sci::Line lineStart = line; while (line <= lineMaxSubord) { - pcs->SetVisible(line, line, true); const FoldLevel level = pdoc->GetFoldLevel(line); if (LevelIsHeader(level)) { + pcs->SetVisible(lineStart, line, true); if (pcs->GetExpanded(line)) { line = ExpandLine(line); } else { line = pdoc->GetLastChild(line); } + lineStart = line + 1; } line++; } + if (lineStart <= lineMaxSubord) { + pcs->SetVisible(lineStart, lineMaxSubord, true); + } return lineMaxSubord; } @@ -5588,11 +5593,7 @@ void Editor::FoldAll(FoldAction action) { } if (expanding) { pcs->SetVisible(0, maxLine-1, true); - for (Sci::Line line = 0; line < maxLine; line++) { - if (!pcs->GetExpanded(line)) { - SetFoldExpanded(line, true); - } - } + pcs->ExpandAll(); } else { for (Sci::Line line = 0; line < maxLine; line++) { const FoldLevel level = pdoc->GetFoldLevel(line); diff --git a/test/unit/testContractionState.cxx b/test/unit/testContractionState.cxx index 30d5454f9..0fd391906 100644 --- a/test/unit/testContractionState.cxx +++ b/test/unit/testContractionState.cxx @@ -152,6 +152,28 @@ TEST_CASE("ContractionState") { REQUIRE(true == pcs->GetExpanded(3)); } + SECTION("ExpandAll") { + pcs->InsertLines(0,4); + for (int l=0;l<4;l++) { + REQUIRE(true == pcs->GetExpanded(l)); + } + + pcs->SetExpanded(2, false); + REQUIRE(true == pcs->GetExpanded(1)); + REQUIRE(false == pcs->GetExpanded(2)); + REQUIRE(true == pcs->GetExpanded(3)); + + pcs->SetExpanded(1, false); + REQUIRE(false == pcs->GetExpanded(1)); + REQUIRE(false == pcs->GetExpanded(2)); + REQUIRE(true == pcs->GetExpanded(3)); + + REQUIRE(true == pcs->ExpandAll()); + REQUIRE(true == pcs->GetExpanded(1)); + REQUIRE(true == pcs->GetExpanded(2)); + REQUIRE(true == pcs->GetExpanded(3)); + } + SECTION("ChangeHeight") { pcs->InsertLines(0,4); for (int l=0;l<4;l++) { |