- fix: auto indent processing error when input '{' in the middle of if statement

This commit is contained in:
Roy Qu 2021-12-19 20:48:23 +08:00
parent 34e3360fd3
commit da1dc2e856
2 changed files with 19 additions and 12 deletions

View File

@ -1,6 +1,7 @@
Version 0.11.4 For Dev-C++ 7 Beta Version 0.11.4 For Dev-C++ 7 Beta
- fix: compiler set's custom link parameters not used when compiling - fix: compiler set's custom link parameters not used when compiling
- fix: code completion doesn't work when input inside () or [] - fix: code completion doesn't work when input inside () or []
- fix: auto indent processing error when input '{' in the middle of if statement
Version 0.11.3 For Dev-C++ 7 Beta Version 0.11.3 For Dev-C++ 7 Beta
- fix: use pixel size for fonts, to fit different dpi in multiple displays - fix: use pixel size for fonts, to fit different dpi in multiple displays

View File

@ -2721,13 +2721,14 @@ void SynEdit::doAddChar(QChar AChar)
return; return;
//DoOnPaintTransient(ttBefore); //DoOnPaintTransient(ttBefore);
//mCaretX will change after setSelLength; //mCaretX will change after setSelLength;
int oldCaretX=mCaretX;
int oldCaretY=mCaretY;
if ((mInserting == false) && (!selAvail())) { if ((mInserting == false) && (!selAvail())) {
setSelLength(1); setSelLength(1);
} }
mUndoList->BeginBlock(); mUndoList->BeginBlock();
doSetSelText(AChar);
int oldCaretX=mCaretX-1;
int oldCaretY=mCaretY;
// auto // auto
if (mOptions.testFlag(eoAutoIndent) if (mOptions.testFlag(eoAutoIndent)
&& mHighlighter && mHighlighter
@ -2737,13 +2738,14 @@ void SynEdit::doAddChar(QChar AChar)
//unindent if ':' at end of the line //unindent if ':' at end of the line
if (AChar == ':') { if (AChar == ':') {
QString line = mLines->getString(oldCaretY-1); QString line = mLines->getString(oldCaretY-1);
if (line.length() < oldCaretX) { if (line.length() <= oldCaretX) {
int indentSpaces = calcIndentSpaces(oldCaretY,line+":", true); int indentSpaces = calcIndentSpaces(oldCaretY,line+":", true);
if (indentSpaces != leftSpaces(line)) { if (indentSpaces != leftSpaces(line)) {
QString newLine = GetLeftSpacing(indentSpaces,true) + trimLeft(line); QString newLine = GetLeftSpacing(indentSpaces,true) + trimLeft(line);
int i = newLine.length();
mLines->putString(oldCaretY-1,newLine); mLines->putString(oldCaretY-1,newLine);
internalSetCaretXY(BufferCoord{i+1,oldCaretY}); internalSetCaretXY(BufferCoord{newLine.length()+2,oldCaretY});
setBlockBegin(caretXY());
setBlockEnd(caretXY());
mUndoList->AddChange( mUndoList->AddChange(
SynChangeReason::crDelete, SynChangeReason::crDelete,
BufferCoord{1, oldCaretY}, BufferCoord{1, oldCaretY},
@ -2755,7 +2757,7 @@ void SynEdit::doAddChar(QChar AChar)
SynChangeReason::crInsert, SynChangeReason::crInsert,
BufferCoord{1, oldCaretY}, BufferCoord{1, oldCaretY},
BufferCoord{newLine.length()+1, oldCaretY}, BufferCoord{newLine.length()+1, oldCaretY},
newLine, "",
SynSelectionMode::smNormal SynSelectionMode::smNormal
); );
} }
@ -2763,14 +2765,18 @@ void SynEdit::doAddChar(QChar AChar)
} else if (AChar == '{' || AChar == '}' || AChar == '#') { } else if (AChar == '{' || AChar == '}' || AChar == '#') {
//Reindent line when add '{' '}' and '#' at the beginning //Reindent line when add '{' '}' and '#' at the beginning
QString left = mLines->getString(oldCaretY-1).mid(0,oldCaretX-1); QString left = mLines->getString(oldCaretY-1).mid(0,oldCaretX-1);
qDebug()<<left<<oldCaretX;
// and the first nonblank char is this new { // and the first nonblank char is this new {
if (left.trimmed().isEmpty()) { if (left.trimmed().isEmpty()) {
int indentSpaces = calcIndentSpaces(oldCaretY,AChar, true); int indentSpaces = calcIndentSpaces(oldCaretY,AChar, true);
if (indentSpaces != leftSpaces(left)) { if (indentSpaces != leftSpaces(left)) {
QString right = mLines->getString(oldCaretY-1).mid(oldCaretX); QString right = mLines->getString(oldCaretY-1).mid(oldCaretX-1);
QString newLeft = GetLeftSpacing(indentSpaces,true); QString newLeft = GetLeftSpacing(indentSpaces,true);
mLines->putString(oldCaretY-1,newLeft+right); mLines->putString(oldCaretY-1,newLeft+right);
internalSetCaretXY(BufferCoord{newLeft.length()+1,oldCaretY}); BufferCoord newCaretPos = BufferCoord{newLeft.length()+2,oldCaretY};
internalSetCaretXY(newCaretPos);
setBlockBegin(caretXY());
setBlockEnd(caretXY());
mUndoList->AddChange( mUndoList->AddChange(
SynChangeReason::crDelete, SynChangeReason::crDelete,
BufferCoord{1, oldCaretY}, BufferCoord{1, oldCaretY},
@ -2782,14 +2788,14 @@ void SynEdit::doAddChar(QChar AChar)
SynChangeReason::crInsert, SynChangeReason::crInsert,
BufferCoord{1, oldCaretY}, BufferCoord{1, oldCaretY},
BufferCoord{newLeft.length()+1, oldCaretY}, BufferCoord{newLeft.length()+1, oldCaretY},
newLeft, "",
SynSelectionMode::smNormal SynSelectionMode::smNormal
); );
} }
} }
} }
} }
doSetSelText(AChar);
mUndoList->EndBlock(); mUndoList->EndBlock();
//DoOnPaintTransient(ttAfter); //DoOnPaintTransient(ttAfter);
@ -4121,7 +4127,6 @@ void SynEdit::doUndoItem()
Item->changeStartPos(), Item->changeStartPos(),
Item->changeEndPos()); Item->changeEndPos());
QString TmpStr = selText(); QString TmpStr = selText();
qDebug()<<TmpStr;
setSelTextPrimitiveEx( setSelTextPrimitiveEx(
Item->changeSelMode(), Item->changeSelMode(),
Item->changeStr(), Item->changeStr(),
@ -4795,12 +4800,13 @@ void SynEdit::doSetSelText(const QString &Value)
mBlockBegin = StartOfBlock; mBlockBegin = StartOfBlock;
mBlockEnd = EndOfBlock; mBlockEnd = EndOfBlock;
setSelTextPrimitive(Value); setSelTextPrimitive(Value);
if (!Value.isEmpty() && (mActiveSelectionMode !=SynSelectionMode::smColumn)) if (!Value.isEmpty() && (mActiveSelectionMode !=SynSelectionMode::smColumn)) {
mUndoList->AddChange( mUndoList->AddChange(
SynChangeReason::crInsert, SynChangeReason::crInsert,
StartOfBlock, StartOfBlock,
blockEnd(), "", blockEnd(), "",
mActiveSelectionMode); mActiveSelectionMode);
}
} }
int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynSearchOptions sOptions, PSynSearchBase searchEngine, int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynSearchOptions sOptions, PSynSearchBase searchEngine,