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. --- doc/ScintillaDoc.html | 8 ++++++++ include/Scintilla.h | 1 + include/Scintilla.iface | 7 ++++++- src/ContractionState.cxx | 17 +++++++++++++++++ src/ContractionState.h | 1 + src/Editor.cxx | 15 +++++++++++++++ src/Editor.h | 1 + 7 files changed, 49 insertions(+), 1 deletion(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index fbffd64aa..02747ee69 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -4699,6 +4699,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ SCI_SETFOLDEXPANDED(int line, bool expanded)
SCI_GETFOLDEXPANDED(int line)
+ SCI_CONTRACTEDFOLDNEXT(int lineStart)
SCI_TOGGLEFOLD(int line)
SCI_ENSUREVISIBLE(int line)
SCI_ENSUREVISIBLEENFORCEPOLICY(int @@ -4849,6 +4850,13 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ until you had finished. See SciTEBase::FoldAll() and SciTEBase::Expand() for examples of the use of these messages.

+

SCI_CONTRACTEDFOLDNEXT(int lineStart)
+ Search efficiently for lines that are contracted fold headers. + This is useful when saving the user's folding when switching documents or saving folding with a file. + The search starts at line number lineStart and continues forwards to the end of the file. + lineStart is returned if it is a contracted fold header otherwise the next contracted + fold header is returned. If there are no more contracted fold headers then -1 is returned.

+

SCI_ENSUREVISIBLE(int line)
SCI_ENSUREVISIBLEENFORCEPOLICY(int line)
A line may be hidden because more than one of its parent lines is contracted. Both these diff --git a/include/Scintilla.h b/include/Scintilla.h index c20a063f9..54f104437 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -786,6 +786,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_ROTATESELECTION 2606 #define SCI_SWAPMAINANCHORCARET 2607 #define SCI_CHANGELEXERSTATE 2617 +#define SCI_CONTRACTEDFOLDNEXT 2618 #define SCI_STARTRECORD 3001 #define SCI_STOPRECORD 3002 #define SCI_SETLEXER 4001 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 2516b7134..679bce53b 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -304,7 +304,8 @@ fun void MarkerDeleteAll=2045(int markerNumber,) # Get a bit mask of all the markers set on a line. fun int MarkerGet=2046(int line,) -# Find the next line after lineStart that includes a marker in mask. +# Find the next line at or after lineStart that includes a marker in mask. +# Return -1 when no more lines. fun int MarkerNext=2047(int lineStart, int markerMask) # Find the previous line before lineStart that includes a marker in mask. @@ -2090,6 +2091,10 @@ fun void SwapMainAnchorCaret=2607(,) # there may be a need to redraw. fun int ChangeLexerState=2617(position start, position end) +# Find the next line at or after lineStart that is a contracted fold header line. +# Return -1 when no more lines. +fun int ContractedFoldNext=2618(int lineStart,) + # Start notifying the container of all key presses and commands. fun void StartRecord=3001(,) 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