From 518ce3f31af65e2b07bca2c3b8675699148b2718 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 3 Mar 2024 20:58:51 +0800 Subject: [PATCH] optimization for token color settings --- RedPandaIDE/editor.cpp | 34 +++++++++++++----------------- libs/qsynedit/qsynedit/painter.cpp | 7 +++--- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 33a1d56d..c9a4f18c 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -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 && pos1identifierAttribute()->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()<findStatementOf(mFilename, - // s , p.Line); + StatementKind kind; if (mParser->parsing()){ kind=mIdentCache.value(QString("%1 %2").arg(aChar).arg(token),StatementKind::skUnknown); @@ -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) || ( @@ -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()); @@ -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()<mActiveLineColor.isValid() && bCurrentLine)) { // Background = colEditorBG(); // } + + mEdit->onPreparePaintHighlightToken(line,mEdit->mSyntaxer->getTokenPos()+1, + token,attri,style,foreground,background); + if (!background.isValid() ) { background = colEditorBG(); } @@ -671,9 +675,6 @@ void QSynEditPainter::addHighlightToken( 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);