Skip to content

Commit

Permalink
optimization for token color settings
Browse files Browse the repository at this point in the history
  • Loading branch information
royqh1979 committed Mar 3, 2024
1 parent 3f2a0b4 commit 518ce3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
34 changes: 15 additions & 19 deletions RedPandaIDE/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,32 +1235,27 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
return;

if (mParser && syntaxer()) {
// ifdef lines
if (!mParser->isLineVisible(mFilename, line)) {
if (syntaxer()->commentAttribute()->foreground().isValid())
foreground = syntaxer()->commentAttribute()->foreground();
if (syntaxer()->commentAttribute()->background().isValid())
background = syntaxer()->commentAttribute()->background();
foreground = syntaxer()->commentAttribute()->foreground();
background = syntaxer()->commentAttribute()->background();
return;
}
QString lineText = document()->getLine(line-1);
if (mParser->isIncludeLine(lineText)) {
// #include header names (<>)
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();
foreground = syntaxer()->identifierAttribute()->foreground();
background = syntaxer()->identifierAttribute()->background();
}
return;
} else if (mParser->enabled() && attr->tokenType() == QSynedit::TokenType::Identifier) {
//Syntax color for different identifier types
QSynedit::BufferCoord p{aChar,line};
// BufferCoord pBeginPos,pEndPos;
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
// qDebug()<<s;
// PStatement statement = mParser->findStatementOf(mFilename,
// s , p.Line);

StatementKind kind;
if (mParser->parsing()){
kind=mIdentCache.value(QString("%1 %2").arg(aChar).arg(token),StatementKind::skUnknown);
Expand Down Expand Up @@ -1307,9 +1302,10 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
}
}
}
//selection

if (syntaxer() && attr) {
if (attr->tokenType() == QSynedit::TokenType::Keyword) {
//C++ type keywords
if (CppTypeKeywords.contains(token)
||
(
Expand All @@ -1322,10 +1318,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
PColorSchemeItem item = mStatementColors->value(StatementKind::skKeywordType,PColorSchemeItem());

if (item) {
if (item->foreground().isValid())
foreground = item->foreground();
if (item->background().isValid())
background = item->background();
foreground = item->foreground();
background = item->background();
style.setFlag(QSynedit::FontStyle::fsBold,item->bold());
style.setFlag(QSynedit::FontStyle::fsItalic,item->italic());
style.setFlag(QSynedit::FontStyle::fsUnderline,item->underlined());
Expand All @@ -1338,13 +1332,14 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|| (attr->tokenType() == QSynedit::TokenType::Preprocessor)
)
&& (token == mCurrentHighlightedWord)) {
// occurrencies of the selected identifier
if (mCurrentHighlighWordForeground.isValid())
foreground = mCurrentHighlighWordForeground;
if (mCurrentHighlighWordBackground.isValid())
background = mCurrentHighlighWordBackground;
} else if (!selAvail() && attr->name() == SYNS_AttrSymbol
&& pSettings->editor().highlightMathingBraces()) {
// qDebug()<<line<<":"<<aChar<<" - "<<mHighlightCharPos1.Line<<":"<<mHighlightCharPos1.Char<<" - "<<mHighlightCharPos2.Line<<":"<<mHighlightCharPos2.Char;
// matching braces
if ( (line == mHighlightCharPos1.line)
&& (aChar == mHighlightCharPos1.ch)) {
if (mCurrentHighlighWordForeground.isValid())
Expand All @@ -1361,6 +1356,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
}
}
} else {
// occurrencies of the selected word
if (token == mCurrentHighlightedWord) {
if (mCurrentHighlighWordForeground.isValid())
foreground = mCurrentHighlighWordForeground;
Expand Down
7 changes: 4 additions & 3 deletions libs/qsynedit/qsynedit/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,16 +664,17 @@ void QSynEditPainter::addHighlightToken(
// if (!Background.isValid() || (edit->mActiveLineColor.isValid() && bCurrentLine)) {
// Background = colEditorBG();
// }

mEdit->onPreparePaintHighlightToken(line,mEdit->mSyntaxer->getTokenPos()+1,
token,attri,style,foreground,background);

if (!background.isValid() ) {
background = colEditorBG();
}
if (!foreground.isValid()) {
foreground = mEdit->mForegroundColor;
}

mEdit->onPreparePaintHighlightToken(line,mEdit->mSyntaxer->getTokenPos()+1,
token,attri,style,foreground,background);

// Do we have to paint the old chars first, or can we just append?
bool bCanAppend = false;
bool bInitFont = (mTokenAccu.width==0);
Expand Down

0 comments on commit 518ce3f

Please sign in to comment.