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