auto indents for comments

This commit is contained in:
Roy Qu 2022-06-28 12:22:40 +08:00
parent 0985b6444b
commit 2008437342
6 changed files with 21 additions and 4 deletions

View File

@ -1638,11 +1638,12 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
indentAdded = true;
l = commentStartLine;
} else {
//add indent according to the beginning of the comment
//indents according to the beginning of the comment and 2 additional space
additionIndent = 0;
int commentStartLine = findCommentStartLine(startLine-1);
SynRangeState range;
indentSpaces = leftSpaces(startLineText);
range = mDocument->ranges(startLine-1);
indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1))+2;
range = mDocument->ranges(commentStartLine-1);
matchingIndents = range.matchingIndents;
indentAdded = true;
l = startLine;

View File

@ -1042,7 +1042,7 @@ void SynEditTextPainter::PaintLines()
// Paint folding
foldRange = edit->foldStartAtLine(vLine);
if ((foldRange) && foldRange->collapsed) {
sFold = " ... } ";
sFold = edit->highlighter()->foldString();
nFold = edit->stringColumns(sFold,edit->mDocument->lineColumns(vLine-1));
attr = edit->mHighlighter->symbolAttribute();
GetBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel,attr);

View File

@ -85,6 +85,11 @@ QSet<QString> SynHighlighter::keywords() const
return QSet<QString>();
}
QString SynHighlighter::foldString()
{
return " ... }";
}
bool SynHighlighter::isSpaceChar(const QChar &ch)
{
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';

View File

@ -144,6 +144,8 @@ public:
virtual QString languageName() = 0;
virtual SynHighlighterLanguage language() = 0;
virtual QString foldString();
virtual bool isSpaceChar(const QChar& ch);
virtual bool isWordBreakChar(const QChar& ch);
bool enabled() const;

View File

@ -1687,3 +1687,8 @@ QSet<QString> SynEditCppHighlighter::keywords() const
{
return Keywords;
}
QString SynEditCppHighlighter::foldString()
{
return "...}";
}

View File

@ -213,6 +213,10 @@ public:
// SynHighlighter interface
public:
QSet<QString> keywords() const override;
// SynHighlighter interface
public:
QString foldString() override;
};
#endif // SYNEDITCPPHIGHLIGHTER_H