fixes #281: Wrong syntax highlighting for #include lines that contains multiple '>' chars.

This commit is contained in:
Roy Qu 2024-03-17 21:49:06 +08:00
parent 852a451976
commit e7129241e9
2 changed files with 8 additions and 5 deletions

View File

@ -1138,7 +1138,7 @@ bool trySetIncludeUnderline(const QString& lineText, const QChar& quoteStartChar
QSynedit::EditingAreaList &areaList
) {
int pos1=lineText.indexOf(quoteStartChar);
int pos2=lineText.lastIndexOf(quoteEndChar);
int pos2=lineText.indexOf(quoteEndChar,pos1+1);
if (pos1>=0 && pos2>=0 && pos1 < pos2 ) {
QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>();
p->beginX = pos1+2;
@ -1235,7 +1235,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (mParser->isIncludeLine(lineText)) {
// #include header names (<>)
int pos1=lineText.indexOf("<")+1;
int pos2=lineText.lastIndexOf(">")+1;
int pos2=lineText.indexOf(">",pos1);
if (pos1>0 && pos2>0 && pos1<aChar && aChar<pos2) {
style = syntaxer()->identifierAttribute()->styles();
foreground = syntaxer()->identifierAttribute()->foreground();

View File

@ -473,9 +473,9 @@ void QSynEditPainter::paintEditAreas(const EditingAreaList &areaList)
rc.setBottom(rc.bottom()-1);
setDrawingColors(false);
for (const PEditingArea& p:areaList) {
int penWidth = std::max(1,mEdit->font().pixelSize() / 15);
int penWidth = std::max(1.0,std::round(mEdit->font().pixelSize() / 15.0));
if (p->type == EditingAreaType::eatWaveUnderLine)
penWidth = std::max(1,mEdit->font().pixelSize() / 21);
penWidth = std::max(1.0,std::round(mEdit->font().pixelSize() / 21.0));
if (p->beginX > mRight)
continue;
if (p->endX < mLeft)
@ -502,7 +502,10 @@ void QSynEditPainter::paintEditAreas(const EditingAreaList &areaList)
mPainter->drawRect(rc);
break;
case EditingAreaType::eatUnderLine: {
mPainter->drawLine(rc.left(),rc.bottom()-pen.width(),rc.right(),rc.bottom()-pen.width());
int lineHeight = rc.height();
int fontHeight = mPainter->fontMetrics().descent() + mPainter->fontMetrics().ascent();
int linePadding = (lineHeight - fontHeight) / 2;
mPainter->drawLine(rc.left(),rc.bottom()-linePadding-pen.width(),rc.right(),rc.bottom()-linePadding-pen.width());
}
break;
case EditingAreaType::eatWaveUnderLine: {