diff options
author | Jérôme LAFORGE <jerome.laforge@gmail.com> | 2011-12-30 09:57:05 +0100 |
---|---|---|
committer | Jérôme LAFORGE <jerome.laforge@gmail.com> | 2011-12-30 09:57:05 +0100 |
commit | 84e4e42007a88e350d01f1659d2eb38328dae925 (patch) | |
tree | 33d490a30bd7efd5a91e21bbe46b94a422701756 | |
parent | 486a97e37df77f71735444b22d449c0e80cd4db5 (diff) | |
download | scintilla-mirror-84e4e42007a88e350d01f1659d2eb38328dae925.tar.gz |
Fold block of single-line comments.
-rw-r--r-- | lexers/LexSQL.cxx | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lexers/LexSQL.cxx b/lexers/LexSQL.cxx index 60e8101d4..3a8ddeceb 100644 --- a/lexers/LexSQL.cxx +++ b/lexers/LexSQL.cxx @@ -293,6 +293,20 @@ private: } } + bool IsCommentLine (int line, LexAccessor &styler) { + int pos = styler.LineStart(line); + int eol_pos = styler.LineStart(line + 1) - 1; + for (int i = pos; i + 1 < eol_pos; i++) { + int style = styler.StyleAt(i); + // MySQL needs -- comments to be followed by space or control char + if (style == SCE_SQL_COMMENTLINE && styler.Match(i, "--")) + return true; + else if (!IsASpaceOrTab(styler[i])) + return false; + } + return false; + } + OptionsSQL options; OptionSetSQL osSQL; SQLStates sqlStates; @@ -508,8 +522,14 @@ void SCI_METHOD LexerSQL::Fold(unsigned int startPos, int length, int initStyle, int visibleChars = 0; int lineCurrent = styler.GetLine(startPos); int levelCurrent = SC_FOLDLEVELBASE; + if (lineCurrent > 0) { - levelCurrent = styler.LevelAt(lineCurrent - 1) >> 16; + // Backtrack to previous line in case need to fix its fold status for folding block of single-line comments (i.e. '--'). + lineCurrent -= 1; + startPos = styler.LineStart(lineCurrent); + + if (lineCurrent > 0) + levelCurrent = styler.LevelAt(lineCurrent - 1) >> 16; } int levelNext = levelCurrent; char chNext = styler[startPos]; @@ -560,6 +580,13 @@ void SCI_METHOD LexerSQL::Fold(unsigned int startPos, int length, int initStyle, } } } + // Fold block of single-line comments (i.e. '--'). + if (options.foldComment && atEOL && IsCommentLine(lineCurrent, styler)) { + if (!IsCommentLine(lineCurrent - 1, styler) && IsCommentLine(lineCurrent + 1, styler)) + levelNext++; + else if (IsCommentLine(lineCurrent - 1, styler) && !IsCommentLine(lineCurrent + 1, styler)) + levelNext--; + } if (style == SCE_SQL_OPERATOR) { if (ch == '(') { if (levelCurrent > levelNext) |