From 92cc00da5478045a7ae5f6b1a641a123f005e418 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Fri, 29 Oct 2021 17:55:05 +0800 Subject: [PATCH] - fix: indent not correctly calculated - fix: correctly updates cursor position when pasting from clipboard --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 1 + RedPandaIDE/qsynedit/SynEdit.cpp | 27 +++++++++++++----------- RedPandaIDE/qsynedit/highlighter/cpp.cpp | 3 ++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6926abe9..4804c80e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ Version 0.7.5 - enhancement: more accurate auto indent calculation - change: remove "add indent" option in the editor general options widget ( It's merged with "auto indent" option) - enhancement: auto insert a new line when input an enter between '(' and ')' or between '[' and ']' + - fix: correctly updates cursor position when pasting from clipboard Version 0.7.4 - fix: when debug a project, and have breakpoints that not in opened editors, dev-cpp will crash diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 2aeb68b9..4c8d14ef 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -3334,6 +3334,7 @@ void MainWindow::on_actionPaste_triggered() Editor * editor = mEditorList->getEditor(); if (editor != NULL ) { editor->pasteFromClipboard(); + editor->activate(); } } } diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index e4f0957a..8c77c475 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -1390,11 +1390,11 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) // find the indent's start line, and use it's indent as the default indent; QString matchingIndents = rangePreceeding.matchingIndents; int l = startLine-1; - int i = 0; - int len = matchingIndents.length(); while (l>=1) { SynRangeState range = mLines->ranges(l-1); QString newIndents = range.indents.mid(range.firstIndentThisLine); + int i = 0; + int len = matchingIndents.length(); while (i0) indentSpaces+=mTabWidth; break; + } else { + matchingIndents = range.matchingIndents + matchingIndents.mid(i); } l--; } @@ -4855,25 +4857,26 @@ int SynEdit::insertTextByNormalMode(const QString &Value) // } else { // SpaceCount = leftSpaces(sLeftSide); // } + int caretY=mCaretY; // step1: insert the first line of Value into current line Start = 0; P = GetEOL(Value,Start); if (PinsertLines(mCaretY, CountLines(Value,P)); + properSetLine(caretY - 1, Str); + mLines->insertLines(caretY, CountLines(Value,P)); } else { Str = sLeftSide + Value + sRightSide; - properSetLine(mCaretY - 1, Str); + properSetLine(caretY - 1, Str); } - rescanRange(mCaretY); + rescanRange(caretY); // step2: insert remaining lines of Value while (P < Value.length()) { if (Value[P] == '\r') P++; if (Value[P] == '\n') P++; - mCaretY++; + caretY++; mStatusChanges.setFlag(SynStatusChange::scCaretY); Start = P; P = GetEOL(Value,Start); @@ -4888,11 +4891,11 @@ int SynEdit::insertTextByNormalMode(const QString &Value) Str += sRightSide; } if (mOptions.testFlag(eoAutoIndent)) { - int indentSpaces = calcIndentSpaces(mCaretY,Str,true); + int indentSpaces = calcIndentSpaces(caretY,Str,true); Str = GetLeftSpacing(indentSpaces,true)+TrimLeft(Str); } - properSetLine(mCaretY - 1, Str); - rescanRange(mCaretY); + properSetLine(caretY - 1, Str); + rescanRange(caretY); Result++; } bChangeScroll = !mOptions.testFlag(eoScrollPastEol); @@ -4902,9 +4905,9 @@ int SynEdit::insertTextByNormalMode(const QString &Value) mOptions.setFlag(eoScrollPastEol,false); }); if (mOptions.testFlag(eoTrimTrailingSpaces) && (sRightSide == "")) { - internalSetCaretX(lineText().length()+1); + internalSetCaretXY(BufferCoord{lineText().length()+1,caretY}); } else - internalSetCaretX(Str.length() - sRightSide.length()+1); + internalSetCaretXY(BufferCoord{Str.length() - sRightSide.length()+1,caretY}); return Result; } diff --git a/RedPandaIDE/qsynedit/highlighter/cpp.cpp b/RedPandaIDE/qsynedit/highlighter/cpp.cpp index dcdd207e..32f15d4c 100644 --- a/RedPandaIDE/qsynedit/highlighter/cpp.cpp +++ b/RedPandaIDE/qsynedit/highlighter/cpp.cpp @@ -7,7 +7,8 @@ static const QSet StatementKeyWords { "if", "for", "try", - "catch" + "catch", + "else" };