From ff336ad5c3d30946e1eff8febb79347c61d8c38e Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 16 Dec 2022 01:44:20 +0800 Subject: [PATCH] work save --- RedPandaIDE/editor.cpp | 2 +- libs/qsynedit/qsynedit/Constants.cpp | 2 +- libs/qsynedit/qsynedit/TextPainter.cpp | 72 ++++++++++++-------------- libs/qsynedit/qsynedit/TextPainter.h | 4 +- 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index d40bf93a..07258bb8 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -4705,7 +4705,7 @@ void Editor::applySettings() QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo | QSynedit::eoSelectWordByDblClick; - options.setFlag(QSynedit::eoShowSpecialChars); + options.setFlag(QSynedit::eoShowSpecialChars, false); //options options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent()); diff --git a/libs/qsynedit/qsynedit/Constants.cpp b/libs/qsynedit/qsynedit/Constants.cpp index 380e8cc6..7f84ebc3 100644 --- a/libs/qsynedit/qsynedit/Constants.cpp +++ b/libs/qsynedit/qsynedit/Constants.cpp @@ -21,7 +21,7 @@ const QSet WordBreakChars{'.', ',', ';', ':', '"', '\'', '!', '?', '[', ']', '(', ')', '{', '}', '^', '-', '=', '+', '-', '*', '/', '\\', '|'}; const QChar TabGlyph(0x2192); -const QChar SpaceGlyph(0x2027); +const QChar SpaceGlyph('.'); const QChar LineBreakGlyph(0x2193); const QChar SoftBreakGlyph(0x2193); } diff --git a/libs/qsynedit/qsynedit/TextPainter.cpp b/libs/qsynedit/qsynedit/TextPainter.cpp index 64b28bc1..24086c27 100644 --- a/libs/qsynedit/qsynedit/TextPainter.cpp +++ b/libs/qsynedit/qsynedit/TextPainter.cpp @@ -338,7 +338,7 @@ int SynEditTextPainter::columnToXValue(int col) void SynEditTextPainter::paintToken(const QString &token, int tokenCols, int columnsBefore, int first, int last, bool /*isSelection*/, const QFont& font, - const QFont& fontForNonAscii) + const QFont& fontForNonAscii, bool showGlyphs) { bool startPaint; int nX; @@ -392,7 +392,7 @@ void SynEditTextPainter::paintToken(const QString &token, int tokenCols, int col if (token[i].unicode()<=0xFF) { QChar ch; int padding=0; - if (edit->mOptions.testFlag(eoShowSpecialChars)) { + if (showGlyphs) { switch(token[i].unicode()) { case '\t': ch=TabGlyph; @@ -530,24 +530,25 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL) if (bU1) { setDrawingColors(false); rcToken.setRight(columnToXValue(nLineSelStart)); - paintToken(TokenAccu.s,TokenAccu.Columns,TokenAccu.ColumnsBefore,nC1,nLineSelStart,false,font,nonAsciiFont); + paintToken( + TokenAccu.s,TokenAccu.Columns,TokenAccu.ColumnsBefore,nC1,nLineSelStart,false,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); } // selected part of the token setDrawingColors(true); nC1Sel = std::max(nLineSelStart, nC1); nC2Sel = std::min(nLineSelEnd, nC2); rcToken.setRight(columnToXValue(nC2Sel)); - paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1Sel, nC2Sel,true,font,nonAsciiFont); + paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1Sel, nC2Sel,true,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); // second unselected part of the token if (bU2) { setDrawingColors(false); rcToken.setRight(columnToXValue(nC2)); - paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore,nLineSelEnd, nC2,false,font,nonAsciiFont); + paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore,nLineSelEnd, nC2,false,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); } } else { setDrawingColors(bSel); rcToken.setRight(columnToXValue(nC2)); - paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1, nC2,bSel,font,nonAsciiFont); + paintToken(TokenAccu.s, TokenAccu.Columns, TokenAccu.ColumnsBefore, nC1, nC2,bSel,font,nonAsciiFont, TokenAccu.showSpecialGlyphs); } } @@ -589,22 +590,6 @@ void SynEditTextPainter::paintHighlightToken(bool bFillToEOL) } } -bool SynEditTextPainter::tokenIsSpaces(bool &bSpacesTest, const QString& token, bool& bIsSpaces) -{ - if (!bSpacesTest) { - bSpacesTest = true; - for (QChar ch:token) { - //todo: should include tabs? - if (ch!= ' ') { - bIsSpaces = false; - return bIsSpaces; - } - } - bIsSpaces = true; - } - return bIsSpaces; -} - // Store the token chars with the attributes in the TokenAccu // record. This will paint any chars already stored if there is // a (visible) change in the attributes. @@ -614,12 +599,15 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo bool bCanAppend; QColor foreground, background; FontStyles style; - bool bSpacesTest,bIsSpaces; + bool isSpaces=false; + bool showGlyphs=false; if (p_Attri) { foreground = p_Attri->foreground(); background = p_Attri->background(); style = p_Attri->styles(); + isSpaces = p_Attri->tokenType() == TokenType::Space; + showGlyphs = isSpaces && edit->mOptions.testFlag(eoShowSpecialChars); } else { foreground = colFG; background = colBG; @@ -641,17 +629,18 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo // Do we have to paint the old chars first, or can we just append? bCanAppend = false; - bSpacesTest = false; - if (TokenAccu.Columns > 0) { - // font style must be the same or token is only spaces - if (TokenAccu.Style == style || ( (style & FontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline) - && tokenIsSpaces(bSpacesTest,Token,bIsSpaces)) ) { - if ( - // background color must be the same and - ((TokenAccu.BG == background) && - // foreground color must be the same or token is only spaces - ((TokenAccu.FG == foreground) || (tokenIsSpaces(bSpacesTest,Token,bIsSpaces) && !edit->mOptions.testFlag(eoShowSpecialChars))))) { - bCanAppend = true; + if (TokenAccu.Columns > 0 ) { + if (showGlyphs == TokenAccu.showSpecialGlyphs) { + // font style must be the same or token is only spaces + if (TokenAccu.Style == style || ( (style & FontStyle::fsUnderline) == (TokenAccu.Style & fsUnderline) + && isSpaces)) { + if ( + // background color must be the same and + (TokenAccu.BG == background) && + // foreground color must be the same or token is only spaces + ((TokenAccu.FG == foreground) || isSpaces)) { + bCanAppend = true; + } } } // If we can't append it, then we have to paint the old token chars first. @@ -669,6 +658,7 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo TokenAccu.FG = foreground; TokenAccu.BG = background; TokenAccu.Style = style; + TokenAccu.showSpecialGlyphs = showGlyphs; } } @@ -926,17 +916,17 @@ void SynEditTextPainter::paintLines() setDrawingColors(true); rcToken.setLeft(std::max(rcLine.left(), columnToXValue(nLineSelStart))); rcToken.setRight(std::min(rcLine.right(), columnToXValue(nLineSelEnd))); - paintToken(sToken, nTokenColumnLen, 0, nLineSelStart, nLineSelEnd,false,edit->font(),edit->fontForNonAscii()); + paintToken(sToken, nTokenColumnLen, 0, nLineSelStart, nLineSelEnd,false,edit->font(),edit->fontForNonAscii(),false); setDrawingColors(false); rcToken.setLeft(std::max(rcLine.left(), columnToXValue(FirstCol))); rcToken.setRight(std::min(rcLine.right(), columnToXValue(nLineSelStart))); - paintToken(sToken, nTokenColumnLen, 0, FirstCol, nLineSelStart,false,edit->font(),edit->fontForNonAscii()); + paintToken(sToken, nTokenColumnLen, 0, FirstCol, nLineSelStart,false,edit->font(),edit->fontForNonAscii(),false); rcToken.setLeft(std::max(rcLine.left(), columnToXValue(nLineSelEnd))); rcToken.setRight(std::min(rcLine.right(), columnToXValue(LastCol))); - paintToken(sToken, nTokenColumnLen, 0, nLineSelEnd, LastCol,true,edit->font(),edit->fontForNonAscii()); + paintToken(sToken, nTokenColumnLen, 0, nLineSelEnd, LastCol,true,edit->font(),edit->fontForNonAscii(),false); } else { setDrawingColors(bLineSelected); - paintToken(sToken, nTokenColumnLen, 0, FirstCol, LastCol,bLineSelected,edit->font(),edit->fontForNonAscii()); + paintToken(sToken, nTokenColumnLen, 0, FirstCol, LastCol,bLineSelected,edit->font(),edit->fontForNonAscii(),false); } //Paint editingAreaBorders if (bCurrentLine && edit->mInputPreeditString.length()>0) { @@ -1047,8 +1037,10 @@ void SynEditTextPainter::paintLines() } } // Draw LineBreak glyph. - if (edit->mOptions.testFlag(eoShowSpecialChars) && (!bLineSelected) && - (!bSpecialLine) && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) { + if (edit->mOptions.testFlag(eoShowSpecialChars) +// && (!bLineSelected) +// && (!bSpecialLine) + && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) { addHighlightToken(LineBreakGlyph, edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol), edit->charColumns(LineBreakGlyph),vLine, edit->mSyntaxer->whitespaceAttribute()); diff --git a/libs/qsynedit/qsynedit/TextPainter.h b/libs/qsynedit/qsynedit/TextPainter.h index 1cf3e226..9cc4d914 100644 --- a/libs/qsynedit/qsynedit/TextPainter.h +++ b/libs/qsynedit/qsynedit/TextPainter.h @@ -35,6 +35,7 @@ class SynEditTextPainter QColor FG; QColor BG; FontStyles Style; + bool showSpecialGlyphs; }; public: @@ -50,10 +51,9 @@ private: int columnToXValue(int col); void paintToken(const QString& token, int tokenLen, int columnsBefore, int first, int last, bool isSelection, const QFont& font, - const QFont& fontForNonAscii); + const QFont& fontForNonAscii, bool showGlyphs); void paintEditAreas(const EditingAreaList& areaList); void paintHighlightToken(bool bFillToEOL); - bool tokenIsSpaces(bool& bSpacesTest, const QString& token, bool& bIsSpaces); void addHighlightToken(const QString& token, int columnsBefore, int tokenColumns, int cLine, PTokenAttribute p_Attri);