diff --git a/NEWS.md b/NEWS.md index fb3a8640..cb28139c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,8 @@ Version 0.6.5 - fix: not correctly parse gdb's output - fix: path not correctly setted for the debugger process - fix: indent line not correctly drawed - + - enhancement: use rainbox color to draw indent guide lines + - implement: highlight matching brackets Version 0.6.4 - fix: code completion popup not show after '->' inputted diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 20bc1409..4e37d444 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -825,6 +825,23 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to } } + if (!selAvail() && attr->name() == SYNS_AttrSymbol) { + qDebug()<name()<<" - "<identifierAttribute())) { @@ -1309,6 +1326,8 @@ void Editor::onStatusChanged(SynStatusChanges changes) if (changes.testFlag(SynStatusChange::scCaretX) || changes.testFlag(SynStatusChange::scCaretY)) { + mHighlightCharPos1 = BufferCoord{0,0}; + mHighlightCharPos2 = BufferCoord{0,0}; if (mTabStopBegin >=0) { if (mTabStopY==caretY()) { if (mLineAfterTabStop.isEmpty()) { @@ -1334,6 +1353,35 @@ void Editor::onStatusChanged(SynStatusChanges changes) clearUserCodeInTabStops(); } } + } else if (!selAvail() && highlighter()){ + // Is there a bracket char before us? + int lineLength = lineText().length(); + int ch = caretX() - 2; + BufferCoord coord; + if (ch>=0 && ch=0 && chsymbolAttribute()) { + BufferCoord complementCharPos = getMatchingBracketEx(coord); + if (!foldHidesLine(coord.Line) + && !foldHidesLine(complementCharPos.Line)) { + mHighlightCharPos1 = coord; + mHighlightCharPos2 = complementCharPos; + invalidateLine(mHighlightCharPos1.Line); + invalidateLine(mHighlightCharPos2.Line); + } + } + } } @@ -1433,6 +1481,21 @@ void Editor::onLinesInserted(int first, int count) } } +bool Editor::isBraceChar(QChar ch) +{ + switch( ch.unicode()) { + case '{': + case '}': + case '[': + case ']': + case '(': + case ')': + return true; + default: + return false; + } +} + void Editor::resetBreakpoints() { mBreakpointLines.clear(); @@ -3542,13 +3605,13 @@ void Editor::applyColorScheme(const QString& schemeName) setOptions(options); highlighterManager.applyColorScheme(highlighter(),schemeName); if (pSettings->editor().rainbowParenthesis()) { - PSynHighlighterAttribute attr0 =createRainbowAttribute(COLOR_SCHEME_BRACE_1, + PSynHighlighterAttribute attr0 =createRainbowAttribute(SYNS_AttrSymbol, schemeName,COLOR_SCHEME_BRACE_1); - PSynHighlighterAttribute attr1 =createRainbowAttribute(COLOR_SCHEME_BRACE_2, + PSynHighlighterAttribute attr1 =createRainbowAttribute(SYNS_AttrSymbol, schemeName,COLOR_SCHEME_BRACE_2); - PSynHighlighterAttribute attr2 =createRainbowAttribute(COLOR_SCHEME_BRACE_3, + PSynHighlighterAttribute attr2 =createRainbowAttribute(SYNS_AttrSymbol, schemeName,COLOR_SCHEME_BRACE_3); - PSynHighlighterAttribute attr3 =createRainbowAttribute(COLOR_SCHEME_BRACE_4, + PSynHighlighterAttribute attr3 =createRainbowAttribute(SYNS_AttrSymbol, schemeName,COLOR_SCHEME_BRACE_4); setRainbowAttrs(attr0,attr1,attr2,attr3); } diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 6abaeeeb..2b7af4ed 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -175,6 +175,7 @@ private slots: void onLinesInserted(int first,int count); private: + bool isBraceChar(QChar ch); void resetBreakpoints(); QChar getCurrentChar(); bool handleSymbolCompletion(QChar key); @@ -261,6 +262,8 @@ private: QString mLineBeforeTabStop; QString mLineAfterTabStop; QList mUserCodeInTabStops; + BufferCoord mHighlightCharPos1; + BufferCoord mHighlightCharPos2; // QWidget interface protected: diff --git a/RedPandaIDE/qsynedit/TextPainter.cpp b/RedPandaIDE/qsynedit/TextPainter.cpp index a797bdf4..d80fb66e 100644 --- a/RedPandaIDE/qsynedit/TextPainter.cpp +++ b/RedPandaIDE/qsynedit/TextPainter.cpp @@ -607,7 +607,6 @@ void SynEditTextPainter::AddHighlightToken(const QString &Token, int ColumnsBefo Foreground = edit->palette().color(QPalette::Text); } - //todo : change char(getTokenPos) to column? edit->onPreparePaintHighlightToken(cLine,edit->mHighlighter->getTokenPos()+1, Token,p_Attri,Style,Foreground,Background); @@ -672,11 +671,27 @@ void SynEditTextPainter::PaintFoldAttributes() while (LastNonBlank + 1 < edit->mLines->count() && edit->mLines->getString(LastNonBlank).trimmed().isEmpty()) LastNonBlank++; LineIndent = edit->getLineIndent(edit->mLines->getString(LastNonBlank)); + int braceLevel = edit->mLines->ranges(LastNonBlank).braceLevel; + int indentLevel = braceLevel ; + if (edit->mTabWidth>0) + indentLevel = LineIndent / edit->mTabWidth; + int levelDiff = std::max(0,braceLevel - indentLevel); // Step horizontal coord - TabSteps = edit->mTabWidth; + //TabSteps = edit->mTabWidth; + TabSteps = 0; + indentLevel = 0; while (TabSteps < LineIndent) { X = TabSteps * edit->mCharWidth + edit->textOffset() - 2; TabSteps+=edit->mTabWidth; + indentLevel++ ; + if (edit->mHighlighter) { + PSynHighlighterAttribute attr = edit->mHighlighter->symbolAttribute(); + GetBraceColorAttr(indentLevel,attr); + if (attr!=edit->mHighlighter->symbolAttribute()) { + dottedPen.setColor(attr->foreground()); + painter->setPen(dottedPen); + } + } // Move to top of vertical line painter->drawLine(X,Y,X,Y+edit->mTextHeight);