Skip to content

Commit

Permalink
- fix: "float" in #include "float.h" is wrong syntax colored.
Browse files Browse the repository at this point in the history
  - enhancement: Unify syntax color for #include header name
  • Loading branch information
royqh1979 committed Mar 3, 2024
1 parent c8cc888 commit 3f2a0b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Red Panda C++ Version 2.27
- fix: Issue #230 Crash when input " in the txt files.
- enhancement: Unique look&feel for the underline shown while ctrl+mouse over #include line.
- enhancement: Better look&feel for the wave underline shown for syntax errors.
- fix: "float" in #include "float.h" is wrong syntax colored.
- enhancement: Unify syntax color for #include header name

Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors.
Expand Down
53 changes: 39 additions & 14 deletions RedPandaIDE/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,33 @@ void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y)
}
}

bool trySetIncludeUnderline(const QString& lineText, const QChar& quoteStartChar,
const QChar& quoteEndChar,
QSynedit::PSyntaxer syntaxer,
QColor foreColor,
QSynedit::EditingAreaList &areaList
) {
int pos1=lineText.indexOf(quoteStartChar);
int pos2=lineText.lastIndexOf(quoteEndChar);
if (pos1>=0 && pos2>=0 && pos1 < pos2 ) {
QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>();
p->beginX = pos1+2;
p->endX = pos2+1;
p->type = QSynedit::EditingAreaType::eatUnderLine;
if (syntaxer) {
if (quoteStartChar=='\"')
p->color = syntaxer->stringAttribute()->foreground();
else
p->color = syntaxer->identifierAttribute()->foreground();
} else {
p->color = foreColor;
}
areaList.append(p);
return true;
}
return false;
}

void Editor::onGetEditingAreas(int line, QSynedit::EditingAreaList &areaList)
{
areaList.clear();
Expand Down Expand Up @@ -1172,20 +1199,8 @@ void Editor::onGetEditingAreas(int line, QSynedit::EditingAreaList &areaList)
QString lineText = document()->getLine(line-1);
if (mParser && mParser->isIncludeLine(lineText)) {
if (line == mHoverModifiedLine) {
int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\""));
int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\""));
if (pos1>=0 && pos2>=0 && pos1 < pos2) {
QSynedit::PEditingArea p=std::make_shared<QSynedit::EditingArea>();
p->beginX = pos1+2;
p->endX = pos2+1;
p->type = QSynedit::EditingAreaType::eatUnderLine;
if (syntaxer()) {
p->color = syntaxer()->identifierAttribute()->foreground();
} else {
p->color = foregroundColor();
}
areaList.append(p);
}
if (!trySetIncludeUnderline(lineText,'<','>',syntaxer(), foregroundColor(), areaList))
trySetIncludeUnderline(lineText,'"','"',syntaxer(), foregroundColor(), areaList);
}
}
}
Expand Down Expand Up @@ -1229,6 +1244,16 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
}
QString lineText = document()->getLine(line-1);
if (mParser->isIncludeLine(lineText)) {
int pos1=lineText.indexOf("<")+1;
int pos2=lineText.lastIndexOf(">")+1;
if (pos1>0 && pos2>0 && pos1<aChar && aChar<pos2) {
style = syntaxer()->identifierAttribute()->styles();
if (syntaxer()->identifierAttribute()->foreground().isValid())
foreground = syntaxer()->identifierAttribute()->foreground();
if (syntaxer()->identifierAttribute()->background().isValid())
background = syntaxer()->identifierAttribute()->background();
}
return;
} else if (mParser->enabled() && attr->tokenType() == QSynedit::TokenType::Identifier) {
QSynedit::BufferCoord p{aChar,line};
// BufferCoord pBeginPos,pEndPos;
Expand Down

0 comments on commit 3f2a0b4

Please sign in to comment.