Merge branch 'master' of github.com:royqh1979/RedPanda-CPP

This commit is contained in:
royqh1979@gmail.com 2021-09-02 12:14:47 +08:00
commit 264e3533d9
2 changed files with 17 additions and 17 deletions

View File

@ -1379,9 +1379,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;
} }

View File

@ -1223,10 +1223,8 @@ BufferCoord SynEdit::WordStartEx(const BufferCoord &XY)
QString Line = mLines->getString(CY - 1); QString Line = mLines->getString(CY - 1);
CX = std::min(CX, Line.length()+1); CX = std::min(CX, Line.length()+1);
if (CX > 1) { if (CX > 1) {
if (isWordChar(Line[CX - 1])) if (isWordChar(Line[CX - 2]))
CX = StrRScanForNonWordChar(Line, CX - 1) + 1; CX = StrRScanForNonWordChar(Line, CX - 1) + 1;
else
CX = StrRScanForWordChar(Line, CX - 1) + 1;
} }
} }
return BufferCoord{CX,CY}; return BufferCoord{CX,CY};
@ -1247,8 +1245,6 @@ BufferCoord SynEdit::WordEndEx(const BufferCoord &XY)
if (CX <= Line.length()) { if (CX <= Line.length()) {
if (isWordChar(Line[CX - 2])) if (isWordChar(Line[CX - 2]))
CX = StrScanForNonWordChar(Line, CX); CX = StrScanForNonWordChar(Line, CX);
else
CX = StrScanForWordChar(Line, CX);
if (CX == 0) if (CX == 0)
CX = Line.length() + 1; CX = Line.length() + 1;
} }
@ -2292,6 +2288,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,32 +2298,32 @@ 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(mCaretX-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
); );