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

Function FoldCSSDoc

scintilla/lexers/LexCSS.cxx:518–566  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516}
517
518static void FoldCSSDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
519 bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
520 bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
521 unsigned int endPos = startPos + length;
522 int visibleChars = 0;
523 int lineCurrent = styler.GetLine(startPos);
524 int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
525 int levelCurrent = levelPrev;
526 char chNext = styler[startPos];
527 bool inComment = (styler.StyleAt(startPos-1) == SCE_CSS_COMMENT);
528 for (unsigned int i = startPos; i < endPos; i++) {
529 char ch = chNext;
530 chNext = styler.SafeGetCharAt(i + 1);
531 int style = styler.StyleAt(i);
532 bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
533 if (foldComment) {
534 if (!inComment && (style == SCE_CSS_COMMENT))
535 levelCurrent++;
536 else if (inComment && (style != SCE_CSS_COMMENT))
537 levelCurrent--;
538 inComment = (style == SCE_CSS_COMMENT);
539 }
540 if (style == SCE_CSS_OPERATOR) {
541 if (ch == '{') {
542 levelCurrent++;
543 } else if (ch == '}') {
544 levelCurrent--;
545 }
546 }
547 if (atEOL) {
548 int lev = levelPrev;
549 if (visibleChars == 0 && foldCompact)
550 lev |= SC_FOLDLEVELWHITEFLAG;
551 if ((levelCurrent > levelPrev) && (visibleChars > 0))
552 lev |= SC_FOLDLEVELHEADERFLAG;
553 if (lev != styler.LevelAt(lineCurrent)) {
554 styler.SetLevel(lineCurrent, lev);
555 }
556 lineCurrent++;
557 levelPrev = levelCurrent;
558 visibleChars = 0;
559 }
560 if (!isspacechar(ch))
561 visibleChars++;
562 }
563 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
564 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
565 styler.SetLevel(lineCurrent, levelPrev | flagsNext);
566}
567
568static const char * const cssWordListDesc[] = {
569 "CSS1 Properties",

Callers

nothing calls this directly

Calls 7

isspacecharFunction · 0.85
GetPropertyIntMethod · 0.80
GetLineMethod · 0.80
LevelAtMethod · 0.80
SafeGetCharAtMethod · 0.80
StyleAtMethod · 0.45
SetLevelMethod · 0.45

Tested by

no test coverage detected