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 | fbeb8e678b79c4631c60de32f20bebafa798209e (patch) | |
tree | 5a03e22694202dccfd608b8ff95a50b902c92be8 /lexers/LexSQL.cxx | |
parent | 3aeb11a8120857d626d3d09237b21513d21328b8 (diff) | |
download | scintilla-mirror-fbeb8e678b79c4631c60de32f20bebafa798209e.tar.gz |
Fold block of single-line comments.
Diffstat (limited to 'lexers/LexSQL.cxx')
-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) |