From bca0a3abc1e400557e2f43159f1fc7766abc2d30 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 7 Nov 2021 11:39:52 +0800 Subject: [PATCH] - fix: indents calculation for the line succeeding "*/" --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 3 -- RedPandaIDE/qsynedit/SynEdit.cpp | 57 ++++++++++++++++++++++---------- RedPandaIDE/qsynedit/SynEdit.h | 2 +- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1bad0d07..81e859c4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ Version 0.8.1 For Dev-C++ 7 Beta - fix: Installer should install the app in "program files", not "program files (x86)" - fix: symbol completion for '/*' not work - fix: javadoc-style docstring indents calculation + - fix: indents calculation for the line succeeding "*/" Version 0.8 For Dev-C++ 7 Beta - fix: find in the current file is not correcly saved in the search history diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index b7fb606d..ca1039d5 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1664,9 +1664,7 @@ bool Editor::handleSymbolCompletion(QChar key) } return false; case '*': - qDebug()<<"???"; status = getQuoteStatus(); - qDebug()<<(int)status; if (pSettings->editor().completeComment() && (status == QuoteStatus::NotQuote)) { return handleMultilineCommentCompletion(); } @@ -1771,7 +1769,6 @@ bool Editor::handleBracketSkip() bool Editor::handleMultilineCommentCompletion() { - qDebug()<=1) { + range = mLines->ranges(commentStartLine-1); + if (!mHighlighter->isLastLineCommentNotFinished(range.state)){ + commentStartLine++; + break; + } + if (!range.matchingIndents.isEmpty() + || range.firstIndentThisLinesetLine(trimmedLineText,line-1); + int statePrePre; + if (startLine>1) { + statePrePre = mLines->ranges(startLine-2).state; + } else { + statePrePre = 0; + } SynRangeState rangeAfterFirstToken = mHighlighter->getRangeState(); QString firstToken = mHighlighter->getToken(); PSynHighlighterAttribute attr = mHighlighter->getTokenAttribute(); @@ -1454,29 +1480,26 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) // it means this line is a docstring, should indents according to // the line the comment beginning , and add 1 additional space additionIndent = 1; - int commentStartLine = startLine-1; + int commentStartLine = findCommentStartLine(startLine-1); + SynRangeState range; + indentSpaces = leftSpaces(mLines->getString(commentStartLine-1)); + range = mLines->ranges(commentStartLine-1); + matchingIndents = range.matchingIndents; + dontAddIndent = true; + l = commentStartLine; + } else if ( mHighlighter->isLastLineCommentNotFinished(statePrePre) + && rangePreceeding.matchingIndents.isEmpty() + && rangePreceeding.firstIndentThisLine>=rangePreceeding.indents.length() + && !mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)) { + // the preceeding line is the end of comment + // we should use the indents of the start line of the comment + int commentStartLine = findCommentStartLine(startLine-2); SynRangeState range; - while (commentStartLine>=1) { - range = mLines->ranges(commentStartLine-1); - if (!mHighlighter->isLastLineCommentNotFinished(range.state)){ - commentStartLine++; - break; - } - if (!range.matchingIndents.isEmpty() - || range.firstIndentThisLinegetString(commentStartLine-1)); range = mLines->ranges(commentStartLine-1); matchingIndents = range.matchingIndents; dontAddIndent = true; l = commentStartLine; - } else if (trimmedS.startsWith("*")) { - // fix indents for line like " */" - indentSpaces--; } else { // we just use infos till preceeding line's end to calc indents matchingIndents = rangePreceeding.matchingIndents; diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 783a3fc5..634aac11 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -514,9 +514,9 @@ private: void setSelWord(); void setWordBlock(BufferCoord Value); + int findCommentStartLine(int searchStartLine); int calcIndentSpaces(int line, const QString& lineText, bool addIndent); - void processGutterClick(QMouseEvent* event); void clearUndo();