- fix: if the proceeding line is a comment, current line should not recalculate indent

- fix: if the proceeding line ends with ':' in comments, current line should not indent
This commit is contained in:
royqh1979 2021-11-06 15:23:28 +08:00
parent 0cb696ae68
commit a30982ffa5
2 changed files with 26 additions and 9 deletions

View File

@ -6,6 +6,8 @@ Version 0.8.1 For Dev-C++ 7 Beta
- enhancement: when problem from competitive companion received, show the problem and problem set views. - enhancement: when problem from competitive companion received, show the problem and problem set views.
- enhancement: set problem's answer source file - enhancement: set problem's answer source file
- enhancement: open the problem's answer source file in editor - enhancement: open the problem's answer source file in editor
- fix: if the proceeding line is a comment, current line should not recalculate indent
- fix: if the proceeding line ends with ':' in comments, current line should not indent
Version 0.8 For Dev-C++ 7 Beta Version 0.8 For Dev-C++ 7 Beta
- fix: find in the current file is not correcly saved in the search history - fix: find in the current file is not correcly saved in the search history

View File

@ -1416,9 +1416,11 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
int indentSpaces = 0; int indentSpaces = 0;
if (startLine>=1) { if (startLine>=1) {
indentSpaces = leftSpaces(s); indentSpaces = leftSpaces(s);
if (addIndent) { SynRangeState rangePreceeding = mLines->ranges(startLine-1);
SynRangeState rangePreceeding = mLines->ranges(startLine-1); mHighlighter->setState(rangePreceeding);
mHighlighter->setState(rangePreceeding); if (addIndent
&& !mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)
&& !mHighlighter->isLastLineStringNotFinished(rangePreceeding.state)) {
mHighlighter->setLine(lineText.trimmed(),line-1); mHighlighter->setLine(lineText.trimmed(),line-1);
SynRangeState rangeAfterFirstToken = mHighlighter->getRangeState(); SynRangeState rangeAfterFirstToken = mHighlighter->getRangeState();
QString firstToken = mHighlighter->getToken(); QString firstToken = mHighlighter->getToken();
@ -1486,12 +1488,25 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
l--; l--;
} }
} }
if (!dontAddIndent && if (!dontAddIndent) {
( if (rangePreceeding.firstIndentThisLine < rangePreceeding.indents.length()) {
(rangePreceeding.firstIndentThisLine < rangePreceeding.indents.length()) // there are indents added at this (preceeding) line indentSpaces += mTabWidth;
|| s.trimmed().endsWith(':')) dontAddIndent = true;
) { }
indentSpaces += mTabWidth; }
if (!dontAddIndent && !s.isEmpty()) {
BufferCoord coord;
QString token;
PSynHighlighterAttribute attr;
coord.Line = startLine;
coord.Char = lines()->getString(startLine-1).length();
if (getHighlighterAttriAtRowCol(coord,token,attr)
&& attr == mHighlighter->symbolAttribute()
&& token == ":") {
indentSpaces += mTabWidth;
dontAddIndent = true;
}
} }
} }
} }