From ff4e20ae18474155c7f1f0207d1b11419e490aac Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Wed, 1 Sep 2021 17:34:39 +0800 Subject: [PATCH 1/3] - fix: indent error when overwrite '}' --- RedPandaIDE/editor.cpp | 5 +++-- RedPandaIDE/qsynedit/SynEdit.cpp | 27 ++++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index eac1232d..3d051752 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -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; } diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 69941a35..eb90c077 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -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 (iputString(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; } } } From 8e3c85e027628aba113b92a1446e76919b248adb Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Wed, 1 Sep 2021 17:39:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20indent=20error=20when=20overwrite=20?= =?UTF-8?q?=E2=80=98}=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RedPandaIDE/qsynedit/SynEdit.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index eb90c077..70ece1e5 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -2314,7 +2314,7 @@ void SynEdit::doAddChar(QChar AChar) while (iputString(oldCaretY-1,temp); internalSetCaretXY(BufferCoord{i+1,oldCaretY}); mUndoList->AddChange( @@ -2331,8 +2331,6 @@ void SynEdit::doAddChar(QChar AChar) "", SynSelectionMode::smNormal ); - mLines->getString(mCaretY-1); - return; } } } From 9fab69b08fc2c936f18877ed1af75eb2a9c2876a Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Wed, 1 Sep 2021 17:44:28 +0800 Subject: [PATCH 3/3] fix: error when insert completion word --- RedPandaIDE/qsynedit/SynEdit.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 70ece1e5..e3c6ea24 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -1223,10 +1223,8 @@ BufferCoord SynEdit::WordStartEx(const BufferCoord &XY) QString Line = mLines->getString(CY - 1); CX = std::min(CX, Line.length()+1); if (CX > 1) { - if (isWordChar(Line[CX - 1])) + if (isWordChar(Line[CX - 2])) CX = StrRScanForNonWordChar(Line, CX - 1) + 1; - else - CX = StrRScanForWordChar(Line, CX - 1) + 1; } } return BufferCoord{CX,CY}; @@ -1247,8 +1245,6 @@ BufferCoord SynEdit::WordEndEx(const BufferCoord &XY) if (CX <= Line.length()) { if (isWordChar(Line[CX - 2])) CX = StrScanForNonWordChar(Line, CX); - else - CX = StrScanForWordChar(Line, CX); if (CX == 0) CX = Line.length() + 1; }