MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / FoldPowerShellDoc

Function FoldPowerShellDoc

scintilla/lexers/LexPowerShell.cxx:161–235  ·  view source on GitHub ↗

Store both the current line's fold level and the next lines in the level store to make it easy to pick up with each increment and to make it possible to fiddle the current level for "} else {".

Source from the content-addressed store, hash-verified

159// level store to make it easy to pick up with each increment
160// and to make it possible to fiddle the current level for "} else {".
161static void FoldPowerShellDoc(unsigned int startPos, int length, int initStyle,
162 WordList *[], Accessor &styler) {
163 bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
164 bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
165 bool foldAtElse = styler.GetPropertyInt("fold.at.else", 0) != 0;
166 unsigned int endPos = startPos + length;
167 int visibleChars = 0;
168 int lineCurrent = styler.GetLine(startPos);
169 int levelCurrent = SC_FOLDLEVELBASE;
170 if (lineCurrent > 0)
171 levelCurrent = styler.LevelAt(lineCurrent-1) >> 16;
172 int levelMinCurrent = levelCurrent;
173 int levelNext = levelCurrent;
174 char chNext = styler[startPos];
175 int styleNext = styler.StyleAt(startPos);
176 int style = initStyle;
177 for (unsigned int i = startPos; i < endPos; i++) {
178 char ch = chNext;
179 chNext = styler.SafeGetCharAt(i + 1);
180 int stylePrev = style;
181 style = styleNext;
182 styleNext = styler.StyleAt(i + 1);
183 bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
184 if (style == SCE_POWERSHELL_OPERATOR) {
185 if (ch == '{') {
186 // Measure the minimum before a '{' to allow
187 // folding on "} else {"
188 if (levelMinCurrent > levelNext) {
189 levelMinCurrent = levelNext;
190 }
191 levelNext++;
192 } else if (ch == '}') {
193 levelNext--;
194 }
195 } else if (foldComment && style == SCE_POWERSHELL_COMMENTSTREAM) {
196 if (stylePrev != SCE_POWERSHELL_COMMENTSTREAM && stylePrev != SCE_POWERSHELL_COMMENTDOCKEYWORD) {
197 levelNext++;
198 } else if (styleNext != SCE_POWERSHELL_COMMENTSTREAM && styleNext != SCE_POWERSHELL_COMMENTDOCKEYWORD) {
199 levelNext--;
200 }
201 } else if (foldComment && style == SCE_POWERSHELL_COMMENT) {
202 if (ch == '#') {
203 unsigned int j = i + 1;
204 while ((j < endPos) && IsASpaceOrTab(styler.SafeGetCharAt(j))) {
205 j++;
206 }
207 if (styler.Match(j, "region")) {
208 levelNext++;
209 } else if (styler.Match(j, "endregion")) {
210 levelNext--;
211 }
212 }
213 }
214 if (!IsASpace(ch))
215 visibleChars++;
216 if (atEOL || (i == endPos-1)) {
217 int levelUse = levelCurrent;
218 if (foldAtElse) {

Callers

nothing calls this directly

Calls 9

IsASpaceOrTabFunction · 0.85
IsASpaceFunction · 0.85
GetPropertyIntMethod · 0.80
GetLineMethod · 0.80
LevelAtMethod · 0.80
SafeGetCharAtMethod · 0.80
StyleAtMethod · 0.45
MatchMethod · 0.45
SetLevelMethod · 0.45

Tested by

no test coverage detected