From 7fb06ca08a70dd9f9549b1e34c7dd38e9ca1413a Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Fri, 24 Sep 2010 13:14:40 +1000 Subject: Added SCI_CONTRACTEDFOLDNEXT as a way to find contracted fold headers efficiently. --- src/ContractionState.cxx | 17 +++++++++++++++++ src/ContractionState.h | 1 + src/Editor.cxx | 15 +++++++++++++++ src/Editor.h | 1 + 4 files changed, 34 insertions(+) (limited to 'src') diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index f2cc2f07b..8a1b486e7 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -193,6 +193,23 @@ bool ContractionState::SetExpanded(int lineDoc, bool expanded_) { } } +int ContractionState::ContractedNext(int lineDocStart) const { + if (OneToOne()) { + return -1; + } else { + Check(); + if (!expanded->ValueAt(lineDocStart)) { + return lineDocStart; + } else { + int lineDocNextChange = expanded->EndRun(lineDocStart); + if (lineDocNextChange < LinesInDoc()) + return lineDocNextChange; + else + return -1; + } + } +} + int ContractionState::GetHeight(int lineDoc) const { if (OneToOne()) { return 1; diff --git a/src/ContractionState.h b/src/ContractionState.h index ba6297512..8e7b39b9b 100644 --- a/src/ContractionState.h +++ b/src/ContractionState.h @@ -51,6 +51,7 @@ public: bool GetExpanded(int lineDoc) const; bool SetExpanded(int lineDoc, bool expanded); + int ContractedNext(int lineDocStart) const; int GetHeight(int lineDoc) const; bool SetHeight(int lineDoc, int height); diff --git a/src/Editor.cxx b/src/Editor.cxx index 762156c23..bca458037 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -6481,6 +6481,18 @@ void Editor::ToggleContraction(int line) { } } +int Editor::ContractedFoldNext(int lineStart) { + for (int line = lineStart; lineLinesTotal(); ) { + if (!cs.GetExpanded(line) && (pdoc->GetLevel(line) & SC_FOLDLEVELHEADERFLAG)) + return line; + line = cs.ContractedNext(line+1); + if (line < 0) + return -1; + } + + return -1; +} + /** * Recurse up from this line to find any folds that prevent this line from being visible * and unfold them all. @@ -7866,6 +7878,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { ToggleContraction(wParam); break; + case SCI_CONTRACTEDFOLDNEXT: + return ContractedFoldNext(wParam); + case SCI_ENSUREVISIBLE: EnsureLineVisible(wParam, false); break; diff --git a/src/Editor.h b/src/Editor.h index aa4fc9236..3f36c9088 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -508,6 +508,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void Expand(int &line, bool doExpand); void ToggleContraction(int line); + int ContractedFoldNext(int lineStart); void EnsureLineVisible(int lineDoc, bool enforcePolicy); int GetTag(char *tagValue, int tagNumber); int ReplaceTarget(bool replacePatterns, const char *text, int length=-1); -- cgit v1.2.3