- fix: indent error when overwrite '}'
This commit is contained in:
parent
0f70658d32
commit
ff4e20ae18
|
@ -1361,9 +1361,10 @@ bool Editor::handleBraceSkip()
|
|||
return false;
|
||||
BufferCoord pos = getMatchingBracket();
|
||||
if (pos.Line != 0) {
|
||||
setBlockBegin(caretXY());
|
||||
setBlockEnd(BufferCoord{caretX() + 1, caretY()});
|
||||
bool oldInsertMode = insertMode();
|
||||
setInsertMode(false); //set mode to overwrite
|
||||
CommandProcessor(SynEditorCommand::ecChar,'}');
|
||||
setInsertMode(oldInsertMode);
|
||||
// setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2292,6 +2292,9 @@ void SynEdit::doAddChar(QChar AChar)
|
|||
if (!AChar.isPrint())
|
||||
return;
|
||||
//DoOnPaintTransient(ttBefore);
|
||||
//mCaretX will change after setSelLength;
|
||||
int oldCaretX=mCaretX;
|
||||
int oldCaretY=mCaretY;
|
||||
if ((mInserting == false) && (!selAvail())) {
|
||||
setSelLength(1);
|
||||
}
|
||||
|
@ -2299,35 +2302,37 @@ void SynEdit::doAddChar(QChar AChar)
|
|||
mUndoList->BeginBlock();
|
||||
if (mOptions.testFlag(eoAddIndent)) {
|
||||
// Remove TabWidth of indent of the current line when typing a }
|
||||
if (AChar == '}' && (mCaretY<=mLines->count())) {
|
||||
QString temp = mLines->getString(mCaretY-1).mid(0,mCaretX-1);
|
||||
if (AChar == '}' && (oldCaretY<=mLines->count())) {
|
||||
QString temp = mLines->getString(oldCaretY-1).mid(0,oldCaretX-1);
|
||||
// and the first nonblank char is this new }
|
||||
if (temp.trimmed().isEmpty()) {
|
||||
BufferCoord MatchBracketPos = GetPreviousLeftBracket(mCaretX, mCaretY);
|
||||
BufferCoord MatchBracketPos = GetPreviousLeftBracket(oldCaretX, oldCaretY);
|
||||
if (MatchBracketPos.Line > 0) {
|
||||
int i = 0;
|
||||
QString matchline = mLines->getString(MatchBracketPos.Line-1);
|
||||
QString line = lineText();
|
||||
QString line = mLines->getString(oldCaretY-1);
|
||||
while (i<matchline.length() && (matchline[i]==' ' || matchline[i]=='\t')) {
|
||||
i++;
|
||||
}
|
||||
QString temp = matchline.mid(0,i) + line.mid(mCaretX-1);
|
||||
mLines->putString(mCaretY-1,temp);
|
||||
internalSetCaretXY(BufferCoord{i,mCaretY});
|
||||
QString temp = matchline.mid(0,i) + line.mid(oldCaretX-1);
|
||||
mLines->putString(oldCaretY-1,temp);
|
||||
internalSetCaretXY(BufferCoord{i+1,oldCaretY});
|
||||
mUndoList->AddChange(
|
||||
SynChangeReason::crDelete,
|
||||
BufferCoord{1, mCaretY},
|
||||
BufferCoord{line.length()+1, mCaretY},
|
||||
BufferCoord{1, oldCaretY},
|
||||
BufferCoord{line.length()+1, oldCaretY},
|
||||
line,
|
||||
SynSelectionMode::smNormal
|
||||
);
|
||||
mUndoList->AddChange(
|
||||
SynChangeReason::crInsert,
|
||||
BufferCoord{1, mCaretY},
|
||||
BufferCoord{temp.length()+1, mCaretY},
|
||||
BufferCoord{1, oldCaretY},
|
||||
BufferCoord{temp.length()+1, oldCaretY},
|
||||
"",
|
||||
SynSelectionMode::smNormal
|
||||
);
|
||||
mLines->getString(mCaretY-1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue