- fix: indent not correctly calculated

- fix: correctly updates cursor position when pasting from clipboard
This commit is contained in:
royqh1979@gmail.com 2021-10-29 17:55:05 +08:00
parent 61a2ed4350
commit 92cc00da54
4 changed files with 19 additions and 13 deletions

View File

@ -2,6 +2,7 @@ Version 0.7.5
- enhancement: more accurate auto indent calculation - enhancement: more accurate auto indent calculation
- change: remove "add indent" option in the editor general options widget ( It's merged with "auto indent" option) - 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 ']' - 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 Version 0.7.4
- fix: when debug a project, and have breakpoints that not in opened editors, dev-cpp will crash - fix: when debug a project, and have breakpoints that not in opened editors, dev-cpp will crash

View File

@ -3334,6 +3334,7 @@ void MainWindow::on_actionPaste_triggered()
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor != NULL ) {
editor->pasteFromClipboard(); editor->pasteFromClipboard();
editor->activate();
} }
} }
} }

View File

@ -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; // find the indent's start line, and use it's indent as the default indent;
QString matchingIndents = rangePreceeding.matchingIndents; QString matchingIndents = rangePreceeding.matchingIndents;
int l = startLine-1; int l = startLine-1;
int i = 0;
int len = matchingIndents.length();
while (l>=1) { while (l>=1) {
SynRangeState range = mLines->ranges(l-1); SynRangeState range = mLines->ranges(l-1);
QString newIndents = range.indents.mid(range.firstIndentThisLine); QString newIndents = range.indents.mid(range.firstIndentThisLine);
int i = 0;
int len = matchingIndents.length();
while (i<len && !newIndents.isEmpty()) { while (i<len && !newIndents.isEmpty()) {
QChar indent = matchingIndents[i]; QChar indent = matchingIndents[i];
int idx = newIndents.lastIndexOf(indent); int idx = newIndents.lastIndexOf(indent);
@ -1410,6 +1410,8 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
if (newIndents.length()>0) if (newIndents.length()>0)
indentSpaces+=mTabWidth; indentSpaces+=mTabWidth;
break; break;
} else {
matchingIndents = range.matchingIndents + matchingIndents.mid(i);
} }
l--; l--;
} }
@ -4855,25 +4857,26 @@ int SynEdit::insertTextByNormalMode(const QString &Value)
// } else { // } else {
// SpaceCount = leftSpaces(sLeftSide); // SpaceCount = leftSpaces(sLeftSide);
// } // }
int caretY=mCaretY;
// step1: insert the first line of Value into current line // step1: insert the first line of Value into current line
Start = 0; Start = 0;
P = GetEOL(Value,Start); P = GetEOL(Value,Start);
if (P<Value.length()) { if (P<Value.length()) {
Str = sLeftSide + TrimLeft(Value.mid(0, P - Start)); Str = sLeftSide + TrimLeft(Value.mid(0, P - Start));
properSetLine(mCaretY - 1, Str); properSetLine(caretY - 1, Str);
mLines->insertLines(mCaretY, CountLines(Value,P)); mLines->insertLines(caretY, CountLines(Value,P));
} else { } else {
Str = sLeftSide + Value + sRightSide; Str = sLeftSide + Value + sRightSide;
properSetLine(mCaretY - 1, Str); properSetLine(caretY - 1, Str);
} }
rescanRange(mCaretY); rescanRange(caretY);
// step2: insert remaining lines of Value // step2: insert remaining lines of Value
while (P < Value.length()) { while (P < Value.length()) {
if (Value[P] == '\r') if (Value[P] == '\r')
P++; P++;
if (Value[P] == '\n') if (Value[P] == '\n')
P++; P++;
mCaretY++; caretY++;
mStatusChanges.setFlag(SynStatusChange::scCaretY); mStatusChanges.setFlag(SynStatusChange::scCaretY);
Start = P; Start = P;
P = GetEOL(Value,Start); P = GetEOL(Value,Start);
@ -4888,11 +4891,11 @@ int SynEdit::insertTextByNormalMode(const QString &Value)
Str += sRightSide; Str += sRightSide;
} }
if (mOptions.testFlag(eoAutoIndent)) { if (mOptions.testFlag(eoAutoIndent)) {
int indentSpaces = calcIndentSpaces(mCaretY,Str,true); int indentSpaces = calcIndentSpaces(caretY,Str,true);
Str = GetLeftSpacing(indentSpaces,true)+TrimLeft(Str); Str = GetLeftSpacing(indentSpaces,true)+TrimLeft(Str);
} }
properSetLine(mCaretY - 1, Str); properSetLine(caretY - 1, Str);
rescanRange(mCaretY); rescanRange(caretY);
Result++; Result++;
} }
bChangeScroll = !mOptions.testFlag(eoScrollPastEol); bChangeScroll = !mOptions.testFlag(eoScrollPastEol);
@ -4902,9 +4905,9 @@ int SynEdit::insertTextByNormalMode(const QString &Value)
mOptions.setFlag(eoScrollPastEol,false); mOptions.setFlag(eoScrollPastEol,false);
}); });
if (mOptions.testFlag(eoTrimTrailingSpaces) && (sRightSide == "")) { if (mOptions.testFlag(eoTrimTrailingSpaces) && (sRightSide == "")) {
internalSetCaretX(lineText().length()+1); internalSetCaretXY(BufferCoord{lineText().length()+1,caretY});
} else } else
internalSetCaretX(Str.length() - sRightSide.length()+1); internalSetCaretXY(BufferCoord{Str.length() - sRightSide.length()+1,caretY});
return Result; return Result;
} }

View File

@ -7,7 +7,8 @@ static const QSet<QString> StatementKeyWords {
"if", "if",
"for", "for",
"try", "try",
"catch" "catch",
"else"
}; };