From 2d7c2145e3250c5cf67ca4eeae1341c2d40414a6 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 4 Jul 2022 10:01:40 +0800 Subject: [PATCH] - enhancement: prevent group undo when caret position changed - fix: undo link break may lose leading spaces refactor undo --- NEWS.md | 2 + RedPandaIDE/cpprefacter.cpp | 22 +- RedPandaIDE/editor.cpp | 208 +-- RedPandaIDE/mainwindow.cpp | 12 +- RedPandaIDE/qsynedit/MiscProcs.cpp | 12 +- RedPandaIDE/qsynedit/SynEdit.cpp | 1537 ++++++++--------- RedPandaIDE/qsynedit/SynEdit.h | 6 +- RedPandaIDE/qsynedit/TextBuffer.cpp | 57 +- RedPandaIDE/qsynedit/TextBuffer.h | 48 +- RedPandaIDE/qsynedit/TextPainter.cpp | 54 +- RedPandaIDE/qsynedit/Types.cpp | 253 +-- RedPandaIDE/qsynedit/Types.h | 50 +- RedPandaIDE/qsynedit/exporter/synexporter.cpp | 32 +- RedPandaIDE/settings.cpp | 1 - 14 files changed, 996 insertions(+), 1298 deletions(-) diff --git a/NEWS.md b/NEWS.md index 685619dc..93187408 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ Red Panda C++ Version 1.1.4 - refactor of undo system - fix: calculation of the code block ranges when inserting/deleting - fix: undo chains + - enhancement: prevent group undo when caret position changed + - fix: undo link break may lose leading spaces Red Panda C++ Version 1.1.3 diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index 3802f7bc..0f94dd88 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -45,7 +45,7 @@ bool CppRefacter::findOccurence(Editor *editor, const BufferCoord &pos) PStatement statement = editor->parser()->findStatementOf( editor->filename(), expression, - pos.Line); + pos.line); // definition of the symbol not found if (!statement) return false; @@ -117,7 +117,7 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt QStringList expression; QChar s=editor->charAt(pos); if (!editor->isIdentChar(s)) { - expression = editor->getExpressionAtPosition(BufferCoord{pos.Char-1,pos.Line}); + expression = editor->getExpressionAtPosition(BufferCoord{pos.ch-1,pos.line}); } else { expression = editor->getExpressionAtPosition(pos); } @@ -125,7 +125,7 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt PStatement oldStatement = editor->parser()->findStatementOf( editor->filename(), expression, - pos.Line); + pos.line); // definition of the symbol not found if (!oldStatement) return; @@ -144,7 +144,7 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt PStatement newStatement = editor->parser()->findStatementOf( editor->filename(), newExpression, - pos.Line); + pos.line); if (newStatement && fullParentName(newStatement) == oldScope) { QMessageBox::critical(editor, tr("Rename Symbol Error"), @@ -231,19 +231,19 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile( if (token == statement->command) { //same name symbol , test if the same statement; BufferCoord p; - p.Line = posY+1; - p.Char = start+1; + p.line = posY+1; + p.ch = start+1; QStringList expression = editor.getExpressionAtPosition(p); PStatement tokenStatement = parser->findStatementOf( filename, - expression, p.Line); + expression, p.line); if (tokenStatement && (tokenStatement->line == statement->line) && (tokenStatement->fileName == statement->fileName)) { PSearchResultTreeItem item = std::make_shared(); item->filename = filename; - item->line = p.Line; + item->line = p.line; item->start = start; item->len = token.length(); item->parent = parentItem.get(); @@ -291,13 +291,13 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & if (token == statement->command) { //same name symbol , test if the same statement; BufferCoord p; - p.Line = posY+1; - p.Char = start; + p.line = posY+1; + p.ch = start; QStringList expression = editor.getExpressionAtPosition(p); PStatement tokenStatement = parser->findStatementOf( filename, - expression, p.Line); + expression, p.line); if (tokenStatement && (tokenStatement->line == statement->line) && (tokenStatement->fileName == statement->fileName)) { diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 10c25566..c4928d85 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -595,7 +595,7 @@ void Editor::keyPressEvent(QKeyEvent *event) if (s=="*/") { BufferCoord p = caretXY(); setBlockBegin(p); - p.Char = lineText().length()+1; + p.ch = lineText().length()+1; setBlockEnd(p); setSelText(""); } @@ -652,10 +652,10 @@ void Editor::keyPressEvent(QKeyEvent *event) s=lineBreak()+"* "; insertString(s,false); BufferCoord p = caretXY(); - p.Line++; - p.Char = document()->getString(p.Line-1).length()+1; + p.line++; + p.ch = document()->getString(p.line-1).length()+1; if (right>0) { - p.Char -=right+1; + p.ch -=right+1; } setCaretXY(p); } @@ -718,7 +718,7 @@ void Editor::keyPressEvent(QKeyEvent *event) if (t.isEmpty()) return; - if (activeSelectionMode()==SynSelectionMode::smColumn) + if (activeSelectionMode()==SynSelectionMode::Column) return; QChar ch = t[0]; @@ -932,7 +932,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to if (cursor() == Qt::PointingHandCursor) { BufferCoord p; if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) { - if (line==p.Line){ + if (line==p.line){ int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\"")); int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\"")); pos1++; @@ -954,15 +954,15 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to PStatement statement = parser()->findStatementOf( filename(), expression, - p.Line); + p.line); StatementKind kind = getKindOfStatement(statement); if (kind == StatementKind::skUnknown) { BufferCoord pBeginPos,pEndPos; QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); - if ((pEndPos.Line>=1) - && (pEndPos.Char>=0) - && (pEndPos.Char+1 < document()->getString(pEndPos.Line-1).length()) - && (document()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) { + if ((pEndPos.line>=1) + && (pEndPos.ch>=0) + && (pEndPos.ch+1 < document()->getString(pEndPos.line-1).length()) + && (document()->getString(pEndPos.line-1)[pEndPos.ch+1] == '(')) { kind = StatementKind::skFunction; } else { kind = StatementKind::skVariable; @@ -983,7 +983,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to if (cursor() == Qt::PointingHandCursor) { BufferCoord p; if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) { - if (line==p.Line && (aChar<=p.Char && p.Charname() == SYNS_AttrSymbol && pSettings->editor().highlightMathingBraces()) { // qDebug()<getString(p.Line - 1); + s = document()->getString(p.line - 1); isIncludeLine = mParser->isIncludeLine(s); if (!isIncludeLine) s = wordAtRowCol(p); @@ -1130,7 +1130,7 @@ bool Editor::event(QEvent *event) !mCompletionPopup->isVisible() && !mHeaderCompletionPopup->isVisible()) { if (pSettings->editor().enableIdentifierToolTips()) - hint = getParserHint(QStringList(),s,p.Line); + hint = getParserHint(QStringList(),s,p.line); } break; case TipType::Identifier: @@ -1139,9 +1139,9 @@ bool Editor::event(QEvent *event) && !mHeaderCompletionPopup->isVisible()) { if (pMainWindow->debugger()->executing() && (pSettings->editor().enableDebugTooltips())) { - showDebugHint(s,p.Line); + showDebugHint(s,p.line); } else if (pSettings->editor().enableIdentifierToolTips()) { //if devEditor.ParserHints { - hint = getParserHint(expression, s, p.Line); + hint = getParserHint(expression, s, p.line); } } break; @@ -1209,7 +1209,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event) BufferCoord p; if (pointToCharLine(event->pos(),p)) { - QString s = document()->getString(p.Line - 1); + QString s = document()->getString(p.line - 1); if (mParser->isIncludeLine(s)) { QString filename = mParser->getHeaderFileName(mFilename,s); Editor * e = pMainWindow->editorList()->getEditorByFilename(filename); @@ -1323,8 +1323,8 @@ void Editor::resizeEvent(QResizeEvent *event) void Editor::copyToClipboard() { if (pSettings->editor().copySizeLimit()) { - int startLine = blockBegin().Line; - int endLine = blockEnd().Line; + int startLine = blockBegin().line; + int endLine = blockEnd().line; if ((endLine-startLine+1) > pSettings->editor().copyLineLimits()) { QMessageBox::critical(pMainWindow,tr("Error"), tr("The text to be copied exceeds count limit!")); @@ -1348,8 +1348,8 @@ void Editor::copyToClipboard() void Editor::cutToClipboard() { if (pSettings->editor().copySizeLimit()) { - int startLine = blockBegin().Line; - int endLine = blockEnd().Line; + int startLine = blockBegin().line; + int endLine = blockEnd().line; if ((endLine-startLine+1) > pSettings->editor().copyLineLimits()) { QMessageBox::critical(pMainWindow,tr("Error"), tr("The text to be cut exceeds count limit!")); @@ -1428,8 +1428,8 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT if ((line<1) || (line>document()->count())) return; pError = std::make_shared(); - p.Char = startChar; - p.Line = line; + p.ch = startChar; + p.line = line; if (startChar >= document()->getString(line-1).length()) { start = 1; token = document()->getString(line-1); @@ -1472,8 +1472,8 @@ void Editor::gotoNextSyntaxIssue() if (iter==mSyntaxIssues.end()) return; BufferCoord p; - p.Char = (*iter)->at(0)->startChar; - p.Line = iter.key(); + p.ch = (*iter)->at(0)->startChar; + p.line = iter.key(); setCaretXY(p); } @@ -1486,8 +1486,8 @@ void Editor::gotoPrevSyntaxIssue() return; iter--; BufferCoord p; - p.Char = (*iter)->at(0)->startChar; - p.Line = iter.key(); + p.ch = (*iter)->at(0)->startChar; + p.line = iter.key(); setCaretXY(p); } @@ -1522,11 +1522,11 @@ Editor::PSyntaxIssueList Editor::getSyntaxIssuesAtLine(int line) Editor::PSyntaxIssue Editor::getSyntaxIssueAtPosition(const BufferCoord &pos) { - PSyntaxIssueList lst = getSyntaxIssuesAtLine(pos.Line); + PSyntaxIssueList lst = getSyntaxIssuesAtLine(pos.line); if (!lst) return PSyntaxIssue(); foreach (const PSyntaxIssue& issue, *lst) { - if (issue->startChar<=pos.Char && pos.Char<=issue->endChar) + if (issue->startChar<=pos.ch && pos.ch<=issue->endChar) return issue; } return PSyntaxIssue(); @@ -1590,8 +1590,8 @@ void Editor::onStatusChanged(SynStatusChanges changes) } } } else if (!selAvail() && highlighter() && pSettings->editor().highlightMathingBraces()){ - invalidateLine(mHighlightCharPos1.Line); - invalidateLine(mHighlightCharPos2.Line); + invalidateLine(mHighlightCharPos1.line); + invalidateLine(mHighlightCharPos2.line); mHighlightCharPos1 = BufferCoord{0,0}; mHighlightCharPos2 = BufferCoord{0,0}; // Is there a bracket char before us? @@ -1599,26 +1599,26 @@ void Editor::onStatusChanged(SynStatusChanges changes) int ch = caretX() - 2; BufferCoord coord; if (ch>=0 && ch=0 && chsymbolAttribute()) { BufferCoord complementCharPos = getMatchingBracketEx(coord); - if (!foldHidesLine(coord.Line) - && !foldHidesLine(complementCharPos.Line)) { + if (!foldHidesLine(coord.line) + && !foldHidesLine(complementCharPos.line)) { mHighlightCharPos1 = coord; mHighlightCharPos2 = complementCharPos; - invalidateLine(mHighlightCharPos1.Line); - invalidateLine(mHighlightCharPos2.Line); + invalidateLine(mHighlightCharPos1.line); + invalidateLine(mHighlightCharPos2.line); } } @@ -1812,8 +1812,8 @@ QStringList Editor::getExpressionAtPosition( QStringList result; if (!highlighter()) return result; - int line = pos.Line-1; - int ch = pos.Char-1; + int line = pos.line-1; + int ch = pos.ch-1; int symbolMatchingLevel = 0; LastSymbolType lastSymbolType=LastSymbolType::None; PSynHighlighter highlighter; @@ -1842,7 +1842,7 @@ QStringList Editor::getExpressionAtPosition( break; } PSynHighlighterAttribute attr = highlighter->getTokenAttribute(); - if ( (line == pos.Line-1) + if ( (line == pos.line-1) && (start<=ch) && (ch<=endPos)) { if (attr==highlighter->commentAttribute() || attr == highlighter->stringAttribute()) { return result; @@ -2035,11 +2035,11 @@ QString Editor::getWordForCompletionSearch(const BufferCoord &pos,bool permitTil QString result = ""; QString s; - s = document()->getString(pos.Line - 1); + s = document()->getString(pos.line - 1); int len = s.length(); - int wordBegin = pos.Char - 1 - 1; //BufferCoord::Char starts with 1 - int wordEnd = pos.Char - 1 - 1; + int wordBegin = pos.ch - 1 - 1; //BufferCoord::Char starts with 1 + int wordEnd = pos.ch - 1 - 1; while ((wordBegin >= 0) && (wordBeginkind == StatementKind::skPreprocessor && !statement->args.isEmpty())) { - QChar nextCh = nextNonSpaceChar(caretY()-1,p.Char-1); + QChar nextCh = nextNonSpaceChar(caretY()-1,p.ch-1); if (nextCh=='(') { funcAddOn = ""; } else if (isIdentChar(nextCh) || nextCh == '"' @@ -3188,8 +3188,8 @@ void Editor::headerCompletionInsert() // delete the part of the word that's already been typed ... BufferCoord p = caretXY(); - int posBegin = p.Char-1; - int posEnd = p.Char-1; + int posBegin = p.ch-1; + int posEnd = p.ch-1; QString sLine = lineText(); while ((posBegin>0) && (isIdentChar(sLine[posBegin-1]) || (sLine[posBegin-1]=='.') || (sLine[posBegin-1]=='+'))) @@ -3198,9 +3198,9 @@ void Editor::headerCompletionInsert() while ((posEnd < sLine.length()) && (isIdentChar(sLine[posEnd]) || (sLine[posEnd]=='.') || (sLine[posBegin-1]=='+'))) posEnd++; - p.Char = posBegin+1; + p.ch = posBegin+1; setBlockBegin(p); - p.Char = posEnd+1; + p.ch = posEnd+1; setBlockEnd(p); setSelText(headerName); @@ -3379,7 +3379,7 @@ Editor::TipType Editor::getTipType(QPoint point, BufferCoord& pos) // do not allow when dragging selection if (isPointInSelection(pos)) return TipType::Selection; - } else if (mParser && mParser->isIncludeLine(document()->getString(pos.Line-1))) { + } else if (mParser && mParser->isIncludeLine(document()->getString(pos.line-1))) { return TipType::Preprocessor; }else if (attr == highlighter()->identifierAttribute()) return TipType::Identifier; @@ -3539,8 +3539,8 @@ void Editor::updateFunctionTip(bool showTip) }); const int maxLines=10; BufferCoord caretPos = caretXY(); - int currentLine = caretPos.Line-1; - int currentChar = caretPos.Char-1; + int currentLine = caretPos.line-1; + int currentChar = caretPos.ch-1; BufferCoord functionNamePos{-1,-1}; bool foundFunctionStart = false; int parenthesisLevel = 0; @@ -3556,7 +3556,7 @@ void Editor::updateFunctionTip(bool showTip) while (currentLine>=0) { QString line = document()->getString(currentLine); - if (currentLine!=caretPos.Line-1) + if (currentLine!=caretPos.line-1) currentChar = line.length(); QStringList tokens; QList positions; @@ -3578,15 +3578,15 @@ void Editor::updateFunctionTip(bool showTip) if (foundFunctionStart) { if (attr!=highlighter()->identifierAttribute()) return; // not a function - functionNamePos.Line = currentLine+1; - functionNamePos.Char = start+1; + functionNamePos.line = currentLine+1; + functionNamePos.ch = start+1; break; } tokens.append(token); positions.append(start); } else if (attr == highlighter()->commentAttribute() - && currentLine == caretPos.Line-1 && start=caretPos.Char) { + && currentLine == caretPos.line-1 && start=caretPos.ch) { return; // in comment, do nothing } highlighter()->next(); @@ -3616,8 +3616,8 @@ void Editor::updateFunctionTip(bool showTip) // found start of function foundFunctionStart = true; if (i>0) { - functionNamePos.Line = currentLine+1; - functionNamePos.Char = positions[i-1]+1; + functionNamePos.line = currentLine+1; + functionNamePos.ch = positions[i-1]+1; } break; } else if (tokens[i]=="[") { @@ -3641,13 +3641,13 @@ void Editor::updateFunctionTip(bool showTip) } } } - if (functionNamePos.Char>=0) + if (functionNamePos.ch>=0) break; currentLine--; - if (caretPos.Line-currentLine>maxLines) + if (caretPos.line-currentLine>maxLines) break; } - isFunction = functionNamePos.Char>=0; + isFunction = functionNamePos.ch>=0; currentParamPos = paramsCount-1; if (!isFunction) return; @@ -3655,8 +3655,8 @@ void Editor::updateFunctionTip(bool showTip) QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation); - int x = pWordBegin.Char-1-1; - QString line = document()->getString(pWordBegin.Line-1); + int x = pWordBegin.ch-1-1; + QString line = document()->getString(pWordBegin.line-1); bool hasPreviousWord=false; while (x>=0) { QChar ch=line[x]; @@ -3674,13 +3674,13 @@ void Editor::updateFunctionTip(bool showTip) if (x >= 0 && hasPreviousWord) { BufferCoord pos = pWordBegin; - pos.Char = x+1; + pos.ch = x+1; QString previousWord = getPreviousWordAtPositionForSuggestion(pos); PStatement statement = mParser->findStatementOf( mFilename, previousWord, - pos.Line); + pos.line); if (statement) { PStatement typeStatement = mParser->findTypeDef(statement,mFilename); if (typeStatement && typeStatement->kind == StatementKind::skClass) { @@ -3703,7 +3703,7 @@ void Editor::updateFunctionTip(bool showTip) pMainWindow->functionTip()->clearTips(); QList statements=mParser->getListOfFunctions(mFilename, s, - functionNamePos.Line); + functionNamePos.line); foreach (const PStatement statement, statements) { pMainWindow->functionTip()->addTip( @@ -3762,11 +3762,11 @@ void Editor::popUserCodeInTabStops() tabStopEnd = n+p->endX+1; } mTabStopY = caretY() + p->y; - newCursorPos.Line = mTabStopY; - newCursorPos.Char = tabStopBegin; + newCursorPos.line = mTabStopY; + newCursorPos.ch = tabStopBegin; setCaretXY(newCursorPos); setBlockBegin(newCursorPos); - newCursorPos.Char = tabStopEnd; + newCursorPos.ch = tabStopEnd; setBlockEnd(newCursorPos); mTabStopBegin = tabStopBegin; @@ -3794,13 +3794,13 @@ void Editor::onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); // qDebug()<findStatementOf(mFilename, - s , p.Line); + s , p.line); StatementKind kind = getKindOfStatement(statement); if (kind == StatementKind::skUnknown) { - if ((pEndPos.Line>=1) - && (pEndPos.Char>=0) - && (pEndPos.Char < document()->getString(pEndPos.Line-1).length()) - && (document()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) { + if ((pEndPos.line>=1) + && (pEndPos.ch>=0) + && (pEndPos.ch < document()->getString(pEndPos.line-1).length()) + && (document()->getString(pEndPos.line-1)[pEndPos.ch] == '(')) { kind = StatementKind::skFunction; } else { kind = StatementKind::skVariable; @@ -3926,7 +3926,7 @@ void Editor::gotoDeclaration(const BufferCoord &pos) PStatement statement = parser()->findStatementOf( filename(), expression, - pos.Line); + pos.line); // QString phrase = getWordAtPosition(this,pos,pBeginPos,pEndPos, WordPurpose::wpInformation); // if (phrase.isEmpty()) // return; @@ -3940,7 +3940,7 @@ void Editor::gotoDeclaration(const BufferCoord &pos) } QString filename; int line; - if (statement->fileName == mFilename && statement->line == pos.Line) { + if (statement->fileName == mFilename && statement->line == pos.line) { filename = statement->definitionFileName; line = statement->definitionLine; } else { @@ -3961,7 +3961,7 @@ void Editor::gotoDefinition(const BufferCoord &pos) PStatement statement = parser()->findStatementOf( filename(), expression, - pos.Line); + pos.line); if (!statement) { // pMainWindow->updateStatusbarMessage(tr("Symbol '%1' not found!").arg(phrase)); @@ -3969,7 +3969,7 @@ void Editor::gotoDefinition(const BufferCoord &pos) } QString filename; int line; - if (statement->definitionFileName == mFilename && statement->definitionLine == pos.Line) { + if (statement->definitionFileName == mFilename && statement->definitionLine == pos.line) { filename = statement->fileName; line = statement->line; } else { @@ -3986,17 +3986,17 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW { QString result = ""; QString s; - if ((p.Line<1) || (p.Line>editor->document()->count())) { + if ((p.line<1) || (p.line>editor->document()->count())) { pWordBegin = p; pWordEnd = p; return ""; } - s = editor->document()->getString(p.Line - 1); + s = editor->document()->getString(p.line - 1); int len = s.length(); - int wordBegin = p.Char - 1 - 1; //BufferCoord::Char starts with 1 - int wordEnd = p.Char - 1 - 1; + int wordBegin = p.ch - 1 - 1; //BufferCoord::Char starts with 1 + int wordEnd = p.ch - 1 - 1; // Copy forward until end of word if (purpose == Editor::WordPurpose::wpEvaluation @@ -4121,10 +4121,10 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW // Get end result result = s.mid(wordBegin+1, wordEnd - wordBegin); - pWordBegin.Line = p.Line; - pWordBegin.Char = wordBegin+1; - pWordEnd.Line = p.Line; - pWordEnd.Char = wordEnd; + pWordBegin.line = p.line; + pWordBegin.ch = wordBegin+1; + pWordEnd.line = p.line; + pWordEnd.ch = wordEnd; // last line still have part of word if (!result.isEmpty() @@ -4135,7 +4135,7 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW || purpose == Editor::WordPurpose::wpEvaluation || purpose == Editor::WordPurpose::wpInformation)) { int i = wordBegin; - int line=p.Line; + int line=p.line; while (line>=1) { while (i>=0) { if (s[i] == ' ' @@ -4155,8 +4155,8 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW } else { BufferCoord highlightPos; BufferCoord pDummy; - highlightPos.Line = line; - highlightPos.Char = i+1; + highlightPos.line = line; + highlightPos.ch = i+1; result = getWordAtPosition(editor, highlightPos,pWordBegin,pDummy,purpose)+result; break; } @@ -4197,14 +4197,14 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW QString Editor::getPreviousWordAtPositionForSuggestion(const BufferCoord &p) { QString result; - if ((p.Line<1) || (p.Line>document()->count())) { + if ((p.line<1) || (p.line>document()->count())) { return ""; } - bool inFunc = testInFunc(p.Char-1,p.Line-1); + bool inFunc = testInFunc(p.ch-1,p.line-1); - QString s = document()->getString(p.Line - 1); + QString s = document()->getString(p.line - 1); int wordBegin; - int wordEnd = p.Char-1; + int wordEnd = p.ch-1; if (wordEnd >= s.length()) wordEnd = s.length()-1; while (true) { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 998f5f5b..492d1137 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -2203,8 +2203,8 @@ void MainWindow::loadLastOpens() if (!editor) continue; BufferCoord pos; - pos.Char = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1); - pos.Line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1); + pos.ch = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1); + pos.line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1); editor->setCaretXY(pos); editor->setTopLine( lastOpenIni.GetLongValue(sectionName,"TopLine", 1) @@ -4002,7 +4002,7 @@ void MainWindow::onEditorContextMenu(const QPoint& pos) mEditorContextMenuPos = pos; int line; if (editor->getPositionOfMouse(p)) { - line=p.Line; + line=p.line; //mouse on editing area menu.addAction(ui->actionCompile_Run); menu.addAction(ui->actionDebug); @@ -6466,16 +6466,16 @@ void MainWindow::on_actionRename_Symbol_triggered() } } QStringList expression = editor->getExpressionAtPosition(oldCaretXY); - if (expression.isEmpty() && oldCaretXY.Char>1) { + if (expression.isEmpty() && oldCaretXY.ch>1) { BufferCoord coord=oldCaretXY; - coord.Char--; + coord.ch--; expression = editor->getExpressionAtPosition(coord); } // Find it's definition PStatement oldStatement = editor->parser()->findStatementOf( editor->filename(), expression, - oldCaretXY.Line); + oldCaretXY.line); // definition of the symbol not found if (!oldStatement) return; diff --git a/RedPandaIDE/qsynedit/MiscProcs.cpp b/RedPandaIDE/qsynedit/MiscProcs.cpp index fff8360d..9c415549 100644 --- a/RedPandaIDE/qsynedit/MiscProcs.cpp +++ b/RedPandaIDE/qsynedit/MiscProcs.cpp @@ -621,16 +621,16 @@ int CountLines(const QString &Line, int start) void ensureNotAfter(BufferCoord &cord1, BufferCoord &cord2) { - if((cord1.Line > cord2.Line) || ( - cord1.Line == cord2.Line && - cord1.Char > cord2.Char)) { + if((cord1.line > cord2.line) || ( + cord1.line == cord2.line && + cord1.ch > cord2.ch)) { std::swap(cord1,cord2); } } BufferCoord minBufferCoord(const BufferCoord &P1, const BufferCoord &P2) { - if ( (P2.Line < P1.Line) || ( (P2.Line == P1.Line) && (P2.Char < P1.Char)) ) { + if ( (P2.line < P1.line) || ( (P2.line == P1.line) && (P2.ch < P1.ch)) ) { return P2; } else { return P1; @@ -639,7 +639,7 @@ BufferCoord minBufferCoord(const BufferCoord &P1, const BufferCoord &P2) BufferCoord maxBufferCoord(const BufferCoord &P1, const BufferCoord &P2) { - if ( (P2.Line > P1.Line) || ( (P2.Line == P1.Line) && (P2.Char > P1.Char)) ) { + if ( (P2.line > P1.line) || ( (P2.line == P1.line) && (P2.ch > P1.ch)) ) { return P2; } else { return P1; @@ -672,5 +672,5 @@ QStringList splitStrings(const QString &text) int calSpanLines(const BufferCoord &startPos, const BufferCoord &endPos) { - return std::abs(endPos.Line - startPos.Line+1); + return std::abs(endPos.line - startPos.line+1); } diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 30d0740e..4e3b0ffd 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -114,8 +114,8 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), this->setLineWidth(1); mInsertCaret = SynEditCaretType::ctVerticalLine; mOverwriteCaret = SynEditCaretType::ctBlock; - mSelectionMode = SynSelectionMode::smNormal; - mActiveSelectionMode = SynSelectionMode::smNormal; + mSelectionMode = SynSelectionMode::Normal; + mActiveSelectionMode = SynSelectionMode::Normal; mReadOnly = false; //stop qt to auto fill background @@ -133,8 +133,8 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), mCaretX = 1; mLastCaretColumn = 1; mCaretY = 1; - mBlockBegin.Char = 1; - mBlockBegin.Line = 1; + mBlockBegin.ch = 1; + mBlockBegin.line = 1; mBlockEnd = mBlockBegin; mOptions = eoAutoIndent | eoDragDropEditing | eoEnhanceEndKey | eoTabIndent | @@ -198,8 +198,8 @@ int SynEdit::displayY() const BufferCoord SynEdit::caretXY() const { BufferCoord result; - result.Char = caretX(); - result.Line = caretY(); + result.ch = caretX(); + result.line = caretY(); return result; } @@ -237,41 +237,41 @@ void SynEdit::setCaretXYEx(bool CallEnsureCursorPosVisible, BufferCoord value) if (vTriggerPaint) doOnPaintTransient(SynTransientType::ttBefore); int nMaxX; - if (value.Line > mDocument->count()) - value.Line = mDocument->count(); - if (mActiveSelectionMode!=SynSelectionMode::smColumn) { - if (value.Line < 1) { + if (value.line > mDocument->count()) + value.line = mDocument->count(); + if (mActiveSelectionMode!=SynSelectionMode::Column) { + if (value.line < 1) { // this is just to make sure if Lines stringlist should be empty - value.Line = 1; + value.line = 1; if (!mOptions.testFlag(SynEditorOption::eoScrollPastEol)) { nMaxX = 1; } else { - nMaxX = getDisplayStringAtLine(value.Line).length()+1; + nMaxX = getDisplayStringAtLine(value.line).length()+1; } } else { - nMaxX = getDisplayStringAtLine(value.Line).length()+1; + nMaxX = getDisplayStringAtLine(value.line).length()+1; } - value.Char = std::min(value.Char,nMaxX); + value.ch = std::min(value.ch,nMaxX); } - value.Char = std::max(value.Char,1); + value.ch = std::max(value.ch,1); // if ((value.Char > nMaxX) && (! (mOptions.testFlag(SynEditorOption::eoScrollPastEol)) ) ) // value.Char = nMaxX; // if (value.Char < 1) // value.Char = 1; - if ((value.Char != mCaretX) || (value.Line != mCaretY)) { + if ((value.ch != mCaretX) || (value.line != mCaretY)) { incPaintLock(); auto action = finally([this]{ decPaintLock(); }); // simply include the flags, fPaintLock is > 0 - if (mCaretX != value.Char) { - mCaretX = value.Char; + if (mCaretX != value.ch) { + mCaretX = value.ch; mStatusChanges.setFlag(SynStatusChange::scCaretX); invalidateLine(mCaretY); } - if (mCaretY != value.Line) { + if (mCaretY != value.line) { int oldCaretY = mCaretY; - mCaretY = value.Line; + mCaretY = value.line; invalidateLine(mCaretY); invalidateGutterLine(mCaretY); invalidateLine(oldCaretY); @@ -311,8 +311,8 @@ void SynEdit::setCaretXYCentered(const BufferCoord &value) setCaretXYEx(false,value); if (selAvail()) invalidateSelection(); - mBlockBegin.Char = mCaretX; - mBlockBegin.Line = mCaretY; + mBlockBegin.ch = mCaretX; + mBlockBegin.line = mCaretY; mBlockEnd = mBlockBegin; ensureCursorPosVisibleEx(true); // but here after block has been set } @@ -349,12 +349,12 @@ bool SynEdit::insertMode() const bool SynEdit::canUndo() const { - return !mReadOnly && mUndoList->CanUndo(); + return !mReadOnly && mUndoList->canUndo(); } bool SynEdit::canRedo() const { - return !mReadOnly && mRedoList->CanUndo(); + return !mReadOnly && mRedoList->canUndo(); } int SynEdit::maxScrollWidth() const @@ -379,7 +379,7 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &XY, QString &Token, { int PosX, PosY, endPos, Start; QString Line; - PosY = XY.Line - 1; + PosY = XY.line - 1; if (mHighlighter && (PosY >= 0) && (PosY < mDocument->count())) { Line = mDocument->getString(PosY); if (PosY == 0) { @@ -388,7 +388,7 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &XY, QString &Token, mHighlighter->setState(mDocument->ranges(PosY-1)); } mHighlighter->setLine(Line, PosY); - PosX = XY.Char; + PosX = XY.ch; if ((PosX > 0) && (PosX <= Line.length())) { while (!mHighlighter->eol()) { Start = mHighlighter->getTokenPos() + 1; @@ -417,7 +417,7 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke { int PosX, PosY, endPos; QString Line; - PosY = XY.Line - 1; + PosY = XY.line - 1; if (mHighlighter && (PosY >= 0) && (PosY < mDocument->count())) { Line = mDocument->getString(PosY); if (PosY == 0) { @@ -426,7 +426,7 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke mHighlighter->setState(mDocument->ranges(PosY-1)); } mHighlighter->setLine(Line, PosY); - PosX = XY.Char; + PosX = XY.ch; if ((PosX > 0) && (PosX <= Line.length())) { while (!mHighlighter->eol()) { Start = mHighlighter->getTokenPos() + 1; @@ -451,31 +451,31 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke void SynEdit::beginUndoBlock() { - mUndoList->BeginBlock(); + mUndoList->beginBlock(); } void SynEdit::endUndoBlock() { - mUndoList->EndBlock(); + mUndoList->endBlock(); } void SynEdit::addCaretToUndo() { BufferCoord p=caretXY(); - mUndoList->AddChange(SynChangeReason::crCaret,p,p,QStringList(), mActiveSelectionMode); + mUndoList->addChange(SynChangeReason::Caret,p,p,QStringList(), mActiveSelectionMode); } void SynEdit::addLeftTopToUndo() { BufferCoord p; - p.Char = leftChar(); - p.Line = topLine(); - mUndoList->AddChange(SynChangeReason::crLeftTop,p,p,QStringList(), mActiveSelectionMode); + p.ch = leftChar(); + p.line = topLine(); + mUndoList->addChange(SynChangeReason::LeftTop,p,p,QStringList(), mActiveSelectionMode); } void SynEdit::addSelectionToUndo() { - mUndoList->AddChange(SynChangeReason::crSelection,mBlockBegin, + mUndoList->addChange(SynChangeReason::Selection,mBlockBegin, mBlockEnd,QStringList(),mActiveSelectionMode); } @@ -510,9 +510,9 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) if (mDocument->count()<1) return BufferCoord{0,0}; // get char at caret - PosX = std::max(APoint.Char,1); - PosY = std::max(APoint.Line,1); - Line = mDocument->getString(APoint.Line - 1); + PosX = std::max(APoint.ch,1); + PosY = std::max(APoint.line,1); + Line = mDocument->getString(APoint.line - 1); if (Line.length() >= PosX ) { Test = Line[PosX-1]; // is it one of the recognized brackets? @@ -529,8 +529,8 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) while (PosX > 1) { PosX--; Test = Line[PosX-1]; - p.Char = PosX; - p.Line = PosY; + p.ch = PosX; + p.line = PosY; if ((Test == BracketInc) || (Test == BracketDec)) { isCommentOrStringOrChar = false; if (getHighlighterAttriAtRowCol(p, vDummy, attr)) @@ -563,8 +563,8 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) while (PosX < Len) { PosX++; Test = Line[PosX-1]; - p.Char = PosX; - p.Line = PosY; + p.ch = PosX; + p.line = PosY; if ((Test == BracketInc) || (Test == BracketDec)) { isCommentOrStringOrChar = false; if (getHighlighterAttriAtRowCol(p, vDummy, attr)) @@ -650,7 +650,7 @@ bool SynEdit::pointToLine(const QPoint &point, int &line) } BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(point.x(),point.y())); - line = coord.Line; + line = coord.line; return true; } @@ -744,10 +744,10 @@ QPoint SynEdit::rowColumnToPixels(const DisplayCoord &coord) const */ DisplayCoord SynEdit::bufferToDisplayPos(const BufferCoord &p) const { - DisplayCoord result {p.Char,p.Line}; + DisplayCoord result {p.ch,p.line}; // Account for tabs and charColumns - if (p.Line-1 count()) - result.Column = charToColumn(p.Line,p.Char); + if (p.line-1 count()) + result.Column = charToColumn(p.line,p.ch); // Account for code folding if (mUseCodeFolding) result.Row = foldLineToRow(result.Row); @@ -764,23 +764,23 @@ BufferCoord SynEdit::displayToBufferPos(const DisplayCoord &p) const BufferCoord Result{p.Column,p.Row}; // Account for code folding if (mUseCodeFolding) - Result.Line = foldRowToLine(p.Row); + Result.line = foldRowToLine(p.Row); // Account for tabs - if (Result.Line <= mDocument->count() ) { - Result.Char = columnToChar(Result.Line,p.Column); + if (Result.line <= mDocument->count() ) { + Result.ch = columnToChar(Result.line,p.Column); } return Result; } -ContentsCoord SynEdit::fromBufferCoord(const BufferCoord &p) const -{ - return createNormalizedBufferCoord(p.Char,p.Line); -} +//ContentsCoord SynEdit::fromBufferCoord(const BufferCoord &p) const +//{ +// return createNormalizedBufferCoord(p.Char,p.Line); +//} -ContentsCoord SynEdit::createNormalizedBufferCoord(int aChar, int aLine) const -{ - return ContentsCoord(this,aChar,aLine); -} +//ContentsCoord SynEdit::createNormalizedBufferCoord(int aChar, int aLine) const +//{ +// return ContentsCoord(this,aChar,aLine); +//} //QStringList SynEdit::getContents(const ContentsCoord &pStart, const ContentsCoord &pEnd) //{ @@ -1033,7 +1033,7 @@ void SynEdit::invalidateSelection() { if (mPainterLock>0) return; - invalidateLines(blockBegin().Line, blockEnd().Line); + invalidateLines(blockBegin().line, blockEnd().line); } void SynEdit::invalidateRect(const QRect &rect) @@ -1063,11 +1063,11 @@ void SynEdit::unlockPainter() bool SynEdit::selAvail() const { - if (mBlockBegin.Char == mBlockEnd.Char && mBlockBegin.Line == mBlockEnd.Line) + if (mBlockBegin.ch == mBlockEnd.ch && mBlockBegin.line == mBlockEnd.line) return false; // start line != end line or start char != end char - if (mActiveSelectionMode==SynSelectionMode::smColumn) { - if (mBlockBegin.Line != mBlockEnd.Line) { + if (mActiveSelectionMode==SynSelectionMode::Column) { + if (mBlockBegin.line != mBlockEnd.line) { DisplayCoord coordBegin = bufferToDisplayPos(mBlockBegin); DisplayCoord coordEnd = bufferToDisplayPos(mBlockEnd); return coordBegin.Column!=coordEnd.Column; @@ -1079,11 +1079,11 @@ bool SynEdit::selAvail() const bool SynEdit::colSelAvail() const { - if (mActiveSelectionMode != SynSelectionMode::smColumn) + if (mActiveSelectionMode != SynSelectionMode::Column) return false; - if (mBlockBegin.Char == mBlockEnd.Char && mBlockBegin.Line == mBlockEnd.Line) + if (mBlockBegin.ch == mBlockEnd.ch && mBlockBegin.line == mBlockEnd.line) return false; - if (mBlockBegin.Line == mBlockEnd.Line && mBlockBegin.Char!=mBlockBegin.Char) + if (mBlockBegin.line == mBlockEnd.line && mBlockBegin.ch!=mBlockBegin.ch) return true; DisplayCoord coordBegin = bufferToDisplayPos(mBlockBegin); DisplayCoord coordEnd = bufferToDisplayPos(mBlockEnd); @@ -1097,15 +1097,15 @@ QString SynEdit::wordAtCursor() QString SynEdit::wordAtRowCol(const BufferCoord &pos) { - if ((pos.Line >= 1) && (pos.Line <= mDocument->count())) { - QString line = mDocument->getString(pos.Line - 1); + if ((pos.line >= 1) && (pos.line <= mDocument->count())) { + QString line = mDocument->getString(pos.line - 1); int len = line.length(); if (len == 0) return ""; - if (pos.Char<1 || pos.Char>len) + if (pos.ch<1 || pos.ch>len) return ""; - int start = pos.Char - 1; + int start = pos.ch - 1; if ((start> 0) && !isIdentChar(line[start])) start--; @@ -1124,14 +1124,14 @@ QString SynEdit::wordAtRowCol(const BufferCoord &pos) QChar SynEdit::charAt(const BufferCoord &pos) { - if ((pos.Line >= 1) && (pos.Line <= mDocument->count())) { - QString line = mDocument->getString(pos.Line-1); + if ((pos.line >= 1) && (pos.line <= mDocument->count())) { + QString line = mDocument->getString(pos.line-1); int len = line.length(); if (len == 0) return QChar(0); - if (pos.Char<1 || pos.Char>len) + if (pos.ch<1 || pos.ch>len) return QChar(0); - return line[pos.Char-1]; + return line[pos.ch-1]; } return QChar(0); } @@ -1177,15 +1177,11 @@ QChar SynEdit::lastNonSpaceChar(int line, int ch) void SynEdit::setCaretAndSelection(const BufferCoord &ptCaret, const BufferCoord &ptSelBegin, const BufferCoord &ptSelEnd) { - SynSelectionMode vOldMode = mActiveSelectionMode; incPaintLock(); - auto action = finally([this,vOldMode]{ - mActiveSelectionMode = vOldMode; - decPaintLock(); - }); internalSetCaretXY(ptCaret); setBlockBegin(ptSelBegin); setBlockEnd(ptSelEnd); + decPaintLock(); } bool SynEdit::inputMethodOn() @@ -1247,8 +1243,8 @@ void SynEdit::processGutterClick(QMouseEvent *event) void SynEdit::clearUndo() { - mUndoList->Clear(); - mRedoList->Clear(); + mUndoList->clear(); + mRedoList->clear(); } int SynEdit::findIndentsStartLine(int line, QVector indents) @@ -1310,8 +1306,8 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y) continue; } Test = Line[PosX-1]; - p.Char = PosX; - p.Line = PosY; + p.ch = PosX; + p.line = PosY; if (Test=='{' || Test == '}') { if (getHighlighterAttriAtRowCol(p, vDummy, attr)) { isCommentOrStringOrChar = @@ -1366,20 +1362,20 @@ bool SynEdit::isPointInSelection(const BufferCoord &Value) const { BufferCoord ptBegin = blockBegin(); BufferCoord ptEnd = blockEnd(); - if ((Value.Line >= ptBegin.Line) && (Value.Line <= ptEnd.Line) && - ((ptBegin.Line != ptEnd.Line) || (ptBegin.Char != ptEnd.Char))) { - if (mActiveSelectionMode == SynSelectionMode::smLine) + if ((Value.line >= ptBegin.line) && (Value.line <= ptEnd.line) && + ((ptBegin.line != ptEnd.line) || (ptBegin.ch != ptEnd.ch))) { + if (mActiveSelectionMode == SynSelectionMode::Line) return true; - else if (mActiveSelectionMode == SynSelectionMode::smColumn) { - if (ptBegin.Char > ptEnd.Char) - return (Value.Char >= ptEnd.Char) && (Value.Char < ptBegin.Char); - else if (ptBegin.Char < ptEnd.Char) - return (Value.Char >= ptBegin.Char) && (Value.Char < ptEnd.Char); + else if (mActiveSelectionMode == SynSelectionMode::Column) { + if (ptBegin.ch > ptEnd.ch) + return (Value.ch >= ptEnd.ch) && (Value.ch < ptBegin.ch); + else if (ptBegin.ch < ptEnd.ch) + return (Value.ch >= ptBegin.ch) && (Value.ch < ptEnd.ch); else return false; } else - return ((Value.Line > ptBegin.Line) || (Value.Char >= ptBegin.Char)) && - ((Value.Line < ptEnd.Line) || (Value.Char < ptEnd.Char)); + return ((Value.line > ptBegin.line) || (Value.ch >= ptBegin.ch)) && + ((Value.line < ptEnd.line) || (Value.ch < ptEnd.ch)); } else return false; } @@ -1391,8 +1387,8 @@ BufferCoord SynEdit::nextWordPos() BufferCoord SynEdit::nextWordPosEx(const BufferCoord &XY) { - int CX = XY.Char; - int CY = XY.Line; + int CX = XY.ch; + int CY = XY.line; // valid line? if ((CY >= 1) && (CY <= mDocument->count())) { QString Line = mDocument->getString(CY - 1); @@ -1437,8 +1433,8 @@ BufferCoord SynEdit::wordStart() BufferCoord SynEdit::wordStartEx(const BufferCoord &XY) { - int CX = XY.Char; - int CY = XY.Line; + int CX = XY.ch; + int CY = XY.line; // valid line? if ((CY >= 1) && (CY <= mDocument->count())) { QString Line = mDocument->getString(CY - 1); @@ -1458,8 +1454,8 @@ BufferCoord SynEdit::wordEnd() BufferCoord SynEdit::wordEndEx(const BufferCoord &XY) { - int CX = XY.Char; - int CY = XY.Line; + int CX = XY.ch; + int CY = XY.line; // valid line? if ((CY >= 1) && (CY <= mDocument->count())) { QString Line = mDocument->getString(CY - 1); @@ -1480,8 +1476,8 @@ BufferCoord SynEdit::prevWordPos() BufferCoord SynEdit::prevWordPosEx(const BufferCoord &XY) { - int CX = XY.Char; - int CY = XY.Line; + int CX = XY.ch; + int CY = XY.line; // valid line? if ((CY >= 1) && (CY <= mDocument->count())) { QString Line = mDocument->getString(CY - 1); @@ -1525,17 +1521,17 @@ void SynEdit::setWordBlock(BufferCoord Value) // Value.Char = // else // Value.Char = std::max(Value.Char, 1); - Value.Line = minMax(Value.Line, 1, mDocument->count()); - Value.Char = std::max(Value.Char, 1); - QString TempString = mDocument->getString(Value.Line - 1); //needed for CaretX = LineLength +1 - if (Value.Char > TempString.length()) { - internalSetCaretXY(BufferCoord{TempString.length()+1, Value.Line}); + Value.line = minMax(Value.line, 1, mDocument->count()); + Value.ch = std::max(Value.ch, 1); + QString TempString = mDocument->getString(Value.line - 1); //needed for CaretX = LineLength +1 + if (Value.ch > TempString.length()) { + internalSetCaretXY(BufferCoord{TempString.length()+1, Value.line}); return; } BufferCoord v_WordStart = wordStartEx(Value); BufferCoord v_WordEnd = wordEndEx(Value); - if ((v_WordStart.Line == v_WordEnd.Line) && (v_WordStart.Char < v_WordEnd.Char)) + if ((v_WordStart.line == v_WordEnd.line) && (v_WordStart.ch < v_WordEnd.ch)) setCaretAndSelection(v_WordEnd, v_WordStart, v_WordEnd); } @@ -1726,8 +1722,8 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) BufferCoord coord; QString token; PSynHighlighterAttribute attr; - coord.Line = startLine; - coord.Char = document()->getString(startLine-1).length(); + coord.line = startLine; + coord.ch = document()->getString(startLine-1).length(); if (getHighlighterAttriAtRowCol(coord,token,attr) && attr == mHighlighter->symbolAttribute() && token == ":") { @@ -1744,12 +1740,12 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) void SynEdit::doSelectAll() { BufferCoord LastPt; - LastPt.Char = 1; + LastPt.ch = 1; if (mDocument->empty()) { - LastPt.Line = 1; + LastPt.line = 1; } else { - LastPt.Line = mDocument->count(); - LastPt.Char = mDocument->getString(LastPt.Line-1).length()+1; + LastPt.line = mDocument->count(); + LastPt.ch = mDocument->getString(LastPt.line-1).length()+1; } setCaretAndSelection(caretXY(), BufferCoord{1, 1}, LastPt); // Selection should have changed... @@ -1763,36 +1759,36 @@ void SynEdit::doComment() if (mReadOnly) return; doOnPaintTransient(SynTransientType::ttBefore); - mUndoList->BeginBlock(); + mUndoList->beginBlock(); auto action = finally([this]{ - mUndoList->EndBlock(); + mUndoList->endBlock(); }); origBlockBegin = blockBegin(); origBlockEnd = blockEnd(); origCaret = caretXY(); // Ignore the last line the cursor is placed on - if (origBlockEnd.Char == 1) - endLine = std::max(origBlockBegin.Line - 1, origBlockEnd.Line - 2); + if (origBlockEnd.ch == 1) + endLine = std::max(origBlockBegin.line - 1, origBlockEnd.line - 2); else - endLine = origBlockEnd.Line - 1; - for (int i = origBlockBegin.Line - 1; i<=endLine; i++) { + endLine = origBlockEnd.line - 1; + for (int i = origBlockBegin.line - 1; i<=endLine; i++) { mDocument->putString(i, "//" + mDocument->getString(i)); - mUndoList->AddChange(SynChangeReason::crInsert, + mUndoList->addChange(SynChangeReason::Insert, BufferCoord{1, i + 1}, BufferCoord{3, i + 1}, - QStringList(), SynSelectionMode::smNormal); + QStringList(), SynSelectionMode::Normal); } // When grouping similar commands, process one comment action per undo/redo - mUndoList->AddGroupBreak(); + mUndoList->addGroupBreak(); // Move begin of selection - if (origBlockBegin.Char > 1) - origBlockBegin.Char+=2; + if (origBlockBegin.ch > 1) + origBlockBegin.ch+=2; // Move end of selection - if (origBlockEnd.Char > 1) - origBlockEnd.Char+=2; + if (origBlockEnd.ch > 1) + origBlockEnd.ch+=2; // Move caret - if (origCaret.Char > 1) - origCaret.Char+=2; + if (origCaret.ch > 1) + origCaret.ch+=2; setCaretAndSelection(origCaret, origBlockBegin, origBlockEnd); } @@ -1806,19 +1802,19 @@ void SynEdit::doUncomment() if (mReadOnly) return; doOnPaintTransient(SynTransientType::ttBefore); - mUndoList->BeginBlock(); + mUndoList->beginBlock(); auto action = finally([this]{ - mUndoList->EndBlock(); + mUndoList->endBlock(); }); origBlockBegin = blockBegin(); origBlockEnd = blockEnd(); origCaret = caretXY(); // Ignore the last line the cursor is placed on - if (origBlockEnd.Char == 1) - endLine = std::max(origBlockBegin.Line - 1, origBlockEnd.Line - 2); + if (origBlockEnd.ch == 1) + endLine = std::max(origBlockBegin.line - 1, origBlockEnd.line - 2); else - endLine = origBlockEnd.Line - 1; - for (int i = origBlockBegin.Line - 1; i<= endLine; i++) { + endLine = origBlockEnd.line - 1; + for (int i = origBlockBegin.line - 1; i<= endLine; i++) { s = mDocument->getString(i); // Find // after blanks only int j = 0; @@ -1827,23 +1823,23 @@ void SynEdit::doUncomment() if ((j + 1 < s.length()) && (s[j] == '/') && (s[j + 1] == '/')) { s.remove(j,2); mDocument->putString(i,s); - mUndoList->AddChange(SynChangeReason::crDelete, + mUndoList->addChange(SynChangeReason::Delete, BufferCoord{j+1, i + 1}, BufferCoord{j + 3, i + 1}, - changeText, SynSelectionMode::smNormal); + changeText, SynSelectionMode::Normal); // Move begin of selection - if ((i == origBlockBegin.Line - 1) && (origBlockBegin.Char > 1)) - origBlockBegin.Char-=2; + if ((i == origBlockBegin.line - 1) && (origBlockBegin.ch > 1)) + origBlockBegin.ch-=2; // Move end of selection - if ((i == origBlockEnd.Line - 1) && (origBlockEnd.Char > 1)) - origBlockEnd.Char-=2; + if ((i == origBlockEnd.line - 1) && (origBlockEnd.ch > 1)) + origBlockEnd.ch-=2; // Move caret - if ((i == origCaret.Line - 1) && (origCaret.Char > 1)) - origCaret.Char-=2; + if ((i == origCaret.line - 1) && (origCaret.ch > 1)) + origCaret.ch-=2; } } // When grouping similar commands, process one uncomment action per undo/redo - mUndoList->AddGroupBreak(); + mUndoList->addGroupBreak(); setCaretAndSelection(origCaret,origBlockBegin,origBlockEnd); } @@ -1856,19 +1852,19 @@ void SynEdit::doToggleComment() if (mReadOnly) return; doOnPaintTransient(SynTransientType::ttBefore); - mUndoList->BeginBlock(); + mUndoList->beginBlock(); auto action = finally([this]{ - mUndoList->EndBlock(); + mUndoList->endBlock(); }); origBlockBegin = blockBegin(); origBlockEnd = blockEnd(); origCaret = caretXY(); // Ignore the last line the cursor is placed on - if (origBlockEnd.Char == 1) - endLine = std::max(origBlockBegin.Line - 1, origBlockEnd.Line - 2); + if (origBlockEnd.ch == 1) + endLine = std::max(origBlockBegin.line - 1, origBlockEnd.line - 2); else - endLine = origBlockEnd.Line - 1; - for (int i = origBlockBegin.Line - 1; i<= endLine; i++) { + endLine = origBlockEnd.line - 1; + for (int i = origBlockBegin.line - 1; i<= endLine; i++) { s = mDocument->getString(i); // Find // after blanks only int j = 0; @@ -1959,12 +1955,12 @@ void SynEdit::doMouseScroll(bool isDragging) C.Row = minMax(Y, 1, displayLineCount()); } BufferCoord vCaret = displayToBufferPos(C); - if ((caretX() != vCaret.Char) || (caretY() != vCaret.Line)) { - if (mActiveSelectionMode == SynSelectionMode::smColumn) { - int startLine=std::min(mBlockBegin.Line,mBlockEnd.Line); - startLine = std::min(startLine,vCaret.Line); - int endLine=std::max(mBlockBegin.Line,mBlockEnd.Line); - endLine = std::max(endLine,vCaret.Line); + if ((caretX() != vCaret.ch) || (caretY() != vCaret.line)) { + if (mActiveSelectionMode == SynSelectionMode::Column) { + int startLine=std::min(mBlockBegin.line,mBlockEnd.line); + startLine = std::min(startLine,vCaret.line); + int endLine=std::max(mBlockBegin.line,mBlockEnd.line); + endLine = std::max(endLine,vCaret.line); int currentCol=displayXY().Column; for (int i=startLine;i<=endLine;i++) { @@ -1990,6 +1986,9 @@ void SynEdit::doMouseScroll(bool isDragging) setBlockEnd(mDragSelEndSave); } else setBlockEnd(caretXY()); + + if (mOptions.testFlag(SynEditorOption::eoGroupUndo)) + mUndoList->addGroupBreak(); } computeScroll(isDragging); } @@ -2014,11 +2013,11 @@ void SynEdit::doDeleteLastChar() doOnPaintTransientEx(SynTransientType::ttAfter, true); }); - if (mActiveSelectionMode==SynSelectionMode::smColumn) { + if (mActiveSelectionMode==SynSelectionMode::Column) { BufferCoord start=blockBegin(); BufferCoord end=blockEnd(); if (!selAvail()) { - start.Char--; + start.ch--; setBlockBegin(start); setBlockEnd(end); } @@ -2080,11 +2079,11 @@ void SynEdit::doDeleteLastChar() properSetLine(mCaretY - 1, Temp); } } - if ((Caret.Char != mCaretX) || (Caret.Line != mCaretY)) { - mUndoList->AddChange(SynChangeReason::crDelete, caretXY(), Caret, helper, + if ((Caret.ch != mCaretX) || (Caret.line != mCaretY)) { + mUndoList->addChange(SynChangeReason::Delete, caretXY(), Caret, helper, mActiveSelectionMode); if (shouldAddGroupBreak) - mUndoList->AddGroupBreak(); + mUndoList->addGroupBreak(); } } @@ -2101,11 +2100,11 @@ void SynEdit::doDeleteCurrentChar() doOnPaintTransient(SynTransientType::ttAfter); }); - if (mActiveSelectionMode==SynSelectionMode::smColumn) { + if (mActiveSelectionMode==SynSelectionMode::Column) { BufferCoord start=blockBegin(); BufferCoord end=blockEnd(); if (!selAvail()) { - end.Char++; + end.ch++; setBlockBegin(start); setBlockEnd(end); } @@ -2129,8 +2128,8 @@ void SynEdit::doDeleteCurrentChar() shouldAddGroupBreak=true; // delete char helper.append(QString(ch)); - Caret.Char = mCaretX + 1; - Caret.Line = mCaretY; + Caret.ch = mCaretX + 1; + Caret.line = mCaretY; Temp.remove(mCaretX-1, 1); properSetLine(mCaretY - 1, Temp); } else { @@ -2138,8 +2137,8 @@ void SynEdit::doDeleteCurrentChar() if (mCaretY < mDocument->count()) { shouldAddGroupBreak=true; properSetLine(mCaretY - 1, Temp + mDocument->getString(mCaretY)); - Caret.Char = 1; - Caret.Line = mCaretY + 1; + Caret.ch = 1; + Caret.line = mCaretY + 1; helper.append(""); helper.append(""); mDocument->deleteAt(mCaretY); @@ -2149,11 +2148,11 @@ void SynEdit::doDeleteCurrentChar() doLinesDeleted(mCaretY + 1, 1); } } - if ((Caret.Char != mCaretX) || (Caret.Line != mCaretY)) { - mUndoList->AddChange(SynChangeReason::crDelete, caretXY(), Caret, + if ((Caret.ch != mCaretX) || (Caret.line != mCaretY)) { + mUndoList->addChange(SynChangeReason::Delete, caretXY(), Caret, helper, mActiveSelectionMode); if (shouldAddGroupBreak) - mUndoList->AddGroupBreak(); + mUndoList->addGroupBreak(); } } } @@ -2227,48 +2226,40 @@ void SynEdit::doDeleteLine() if (foldRange && foldRange->collapsed) return; doOnPaintTransient(SynTransientType::ttBefore); - mUndoList->BeginBlock(); - mUndoList->AddChange(SynChangeReason::crCaret, - caretXY(), - caretXY(), - QStringList(), - mActiveSelectionMode); - mUndoList->AddChange(SynChangeReason::crSelection, - mBlockBegin, - mBlockEnd, - QStringList(), - mActiveSelectionMode); + mUndoList->beginBlock(); + addCaretToUndo(); + addSelectionToUndo(); if (selAvail()) setBlockBegin(caretXY()); QStringList helper(lineText()); if (mCaretY == mDocument->count()) { if (mDocument->count()==1) { mDocument->putString(mCaretY - 1,""); - mUndoList->AddChange(SynChangeReason::crDelete, + mUndoList->addChange(SynChangeReason::Delete, BufferCoord{1, mCaretY}, BufferCoord{helper.length() + 1, mCaretY}, - helper, SynSelectionMode::smNormal); + helper, SynSelectionMode::Normal); } else { QString s = mDocument->getString(mCaretY-2); mDocument->deleteAt(mCaretY - 1); helper.insert(0,""); - mUndoList->AddChange(SynChangeReason::crDelete, + mUndoList->addChange(SynChangeReason::Delete, BufferCoord{s.length()+1, mCaretY-1}, BufferCoord{helper.length() + 1, mCaretY}, - helper, SynSelectionMode::smNormal); + helper, SynSelectionMode::Normal); doLinesDeleted(mCaretY, 1); mCaretY--; } } else { mDocument->deleteAt(mCaretY - 1); helper.append(""); - mUndoList->AddChange(SynChangeReason::crDelete, + mUndoList->addChange(SynChangeReason::Delete, BufferCoord{1, mCaretY}, BufferCoord{helper.length() + 1, mCaretY}, - helper, SynSelectionMode::smNormal); + helper, SynSelectionMode::Normal); doLinesDeleted(mCaretY, 1); } - mUndoList->EndBlock(); + mUndoList->endBlock(); internalSetCaretXY(BufferCoord{1, mCaretY}); // like seen in the Delphi editor doOnPaintTransient(SynTransientType::ttAfter); } @@ -2293,16 +2284,15 @@ void SynEdit::doDuplicateLine() doOnPaintTransient(SynTransientType::ttBefore); mDocument->insert(mCaretY, lineText()); doLinesInserted(mCaretY + 1, 1); - mUndoList->BeginBlock(); - mUndoList->AddChange(SynChangeReason::crCaret, - caretXY(),caretXY(),QStringList(),SynSelectionMode::smNormal); - mUndoList->AddChange(SynChangeReason::crLineBreak, + mUndoList->beginBlock(); + addCaretToUndo(); + mUndoList->addChange(SynChangeReason::LineBreak, BufferCoord{s.length()+1,mCaretY}, - BufferCoord{s.length()+1,mCaretY}, QStringList(), SynSelectionMode::smNormal); - mUndoList->AddChange(SynChangeReason::crInsert, + BufferCoord{s.length()+1,mCaretY}, QStringList(), SynSelectionMode::Normal); + mUndoList->addChange(SynChangeReason::Insert, BufferCoord{1,mCaretY+1}, - BufferCoord{s.length()+1,mCaretY+1}, QStringList(), SynSelectionMode::smNormal); - mUndoList->EndBlock(); + BufferCoord{s.length()+1,mCaretY+1}, QStringList(), SynSelectionMode::Normal); + mUndoList->endBlock(); internalSetCaretXY(BufferCoord{1, mCaretY}); // like seen in the Delphi editor doOnPaintTransient(SynTransientType::ttAfter); } @@ -2310,12 +2300,17 @@ void SynEdit::doDuplicateLine() void SynEdit::doMoveSelUp() { - if (mActiveSelectionMode == SynSelectionMode::smColumn) + if (mActiveSelectionMode == SynSelectionMode::Column) return; - if (!mReadOnly && (mDocument->count() > 0) && (blockBegin().Line > 1)) { + if (!mReadOnly && (mDocument->count() > 0) && (blockBegin().line > 1)) { + if (!mUndoing) { + mUndoList->beginBlock(); + addCaretToUndo(); + addSelectionToUndo(); + } BufferCoord origBlockBegin = blockBegin(); BufferCoord origBlockEnd = blockEnd(); - PSynEditFoldRange foldRange=foldStartAtLine(origBlockEnd.Line); + PSynEditFoldRange foldRange=foldStartAtLine(origBlockEnd.line); if (foldRange && foldRange->collapsed) return; // for (int line=origBlockBegin.Line;line<=origBlockEnd.Line;line++) { @@ -2326,36 +2321,28 @@ void SynEdit::doMoveSelUp() doOnPaintTransient(SynTransientType::ttBefore); - // Backup caret and selection + // Delete line above selection + QString s = mDocument->getString(origBlockBegin.line - 2); // before start, 0 based + mDocument->deleteAt(origBlockBegin.line - 2); // before start, 0 based + doLinesDeleted(origBlockBegin.line - 1, 1); // before start, 1 based + // Insert line below selection + mDocument->insert(origBlockEnd.line - 1, s); + doLinesInserted(origBlockEnd.line, 1); + // Restore caret and selection + setCaretAndSelection( + BufferCoord{mCaretX, origBlockBegin.line - 1}, + BufferCoord{origBlockBegin.ch, origBlockBegin.line - 1}, + BufferCoord{origBlockEnd.ch, origBlockEnd.line - 1} + ); if (!mUndoing) { - mUndoList->BeginBlock(); - mUndoList->AddChange(SynChangeReason::crCaret, // backup original caret - caretXY(), - caretXY(), - QStringList(), - SynSelectionMode::smNormal); - mUndoList->AddChange(SynChangeReason::crMoveSelectionUp, + mUndoList->addChange(SynChangeReason::MoveSelectionUp, origBlockBegin, origBlockEnd, QStringList(), - SynSelectionMode::smNormal); - mUndoList->EndBlock(); + SynSelectionMode::Normal); + mUndoList->endBlock(); } - // Delete line above selection - QString s = mDocument->getString(origBlockBegin.Line - 2); // before start, 0 based - mDocument->deleteAt(origBlockBegin.Line - 2); // before start, 0 based - doLinesDeleted(origBlockBegin.Line - 1, 1); // before start, 1 based - - // Insert line below selection - mDocument->insert(origBlockEnd.Line - 1, s); - doLinesInserted(origBlockEnd.Line, 1); - // Restore caret and selection - setCaretAndSelection( - BufferCoord{mCaretX, origBlockBegin.Line - 1}, - BufferCoord{origBlockBegin.Char, origBlockBegin.Line - 1}, - BufferCoord{origBlockEnd.Char, origBlockEnd.Line - 1} - ); doOnPaintTransient(SynTransientType::ttAfter); } @@ -2363,53 +2350,48 @@ void SynEdit::doMoveSelUp() void SynEdit::doMoveSelDown() { - if (mActiveSelectionMode == SynSelectionMode::smColumn) + if (mActiveSelectionMode == SynSelectionMode::Column) return; - if (!mReadOnly && (mDocument->count() > 0) && (blockEnd().Line < mDocument->count())) { + if (!mReadOnly && (mDocument->count() > 0) && (blockEnd().line < mDocument->count())) { + if (!mUndoing) { + mUndoList->beginBlock(); + addCaretToUndo(); + addSelectionToUndo(); + } BufferCoord origBlockBegin = blockBegin(); BufferCoord origBlockEnd = blockEnd(); - PSynEditFoldRange foldRange=foldStartAtLine(origBlockEnd.Line); + + PSynEditFoldRange foldRange=foldStartAtLine(origBlockEnd.line); if (foldRange && foldRange->collapsed) return; -// for (int line=origBlockBegin.Line;line<=origBlockEnd.Line;line++) { -// PSynEditFoldRange foldRange=foldStartAtLine(line.Line); -// if (foldRange && foldRange->collapsed) -// return; -// } + doOnPaintTransient(SynTransientType::ttBefore); - // Backup caret and selection - if (!mUndoing) { - mUndoList->BeginBlock(); - mUndoList->AddChange(SynChangeReason::crCaret, // backup original caret - caretXY(), - caretXY(), - QStringList(), - SynSelectionMode::smNormal); - mUndoList->AddChange(SynChangeReason::crMoveSelectionDown, - origBlockBegin, - origBlockEnd, - QStringList(), - SynSelectionMode::smNormal); - mUndoList->EndBlock(); - } // Delete line below selection - QString s = mDocument->getString(origBlockEnd.Line); // after end, 0 based - mDocument->deleteAt(origBlockEnd.Line); // after end, 0 based - doLinesDeleted(origBlockEnd.Line, 1); // before start, 1 based + QString s = mDocument->getString(origBlockEnd.line); // after end, 0 based + mDocument->deleteAt(origBlockEnd.line); // after end, 0 based + doLinesDeleted(origBlockEnd.line, 1); // before start, 1 based // Insert line above selection - mDocument->insert(origBlockBegin.Line - 1, s); - doLinesInserted(origBlockBegin.Line, 1); + mDocument->insert(origBlockBegin.line - 1, s); + doLinesInserted(origBlockBegin.line, 1); // Restore caret and selection setCaretAndSelection( - BufferCoord{mCaretX, origBlockEnd.Line + 1}, - BufferCoord{origBlockBegin.Char, origBlockBegin.Line + 1}, - BufferCoord{origBlockEnd.Char, origBlockEnd.Line + 1} + BufferCoord{mCaretX, origBlockEnd.line + 1}, + BufferCoord{origBlockBegin.ch, origBlockBegin.line + 1}, + BufferCoord{origBlockEnd.ch, origBlockEnd.line + 1} ); - // Retrieve start of line we moved down + if (!mUndoing) { + mUndoList->addChange(SynChangeReason::MoveSelectionDown, + origBlockBegin, + origBlockEnd, + QStringList(), + SynSelectionMode::Normal); + mUndoList->endBlock(); + } + doOnPaintTransient(SynTransientType::ttAfter); } } @@ -2418,8 +2400,8 @@ void SynEdit::clearAll() { mDocument->clear(); mMarkList.clear(); - mUndoList->Clear(); - mRedoList->Clear(); + mUndoList->clear(); + mRedoList->clear(); setModified(false); } @@ -2429,10 +2411,10 @@ void SynEdit::insertLine(bool moveCaret) return; int nLinesInserted=0; if (!mUndoing) - mUndoList->BeginBlock(); + mUndoList->beginBlock(); auto action = finally([this] { if (!mUndoing) - mUndoList->EndBlock(); + mUndoList->endBlock(); }); QString helper; if (selAvail()) { @@ -2470,6 +2452,9 @@ void SynEdit::insertLine(bool moveCaret) int InsDelta = (mCaretX == 1)?1:0; QString leftLineText = lineText().mid(0, mCaretX - 1); QString rightLineText = lineText().mid(mCaretX-1); + if (!mUndoing) + mUndoList->addChange(SynChangeReason::LineBreak, caretXY(), caretXY(), QStringList(rightLineText), + SynSelectionMode::Normal); bool notInComment=true; properSetLine(mCaretY-1,leftLineText); //update range stated for line mCaretY @@ -2497,9 +2482,6 @@ void SynEdit::insertLine(bool moveCaret) QString indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); mDocument->insert(mCaretY, indentSpacesForRightLineText+rightLineText); nLinesInserted++; - if (!mUndoing) - mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), QStringList(rightLineText), - SynSelectionMode::smNormal); if (!mUndoing) { //insert new line in middle of "/*" and "*/" @@ -2510,8 +2492,8 @@ void SynEdit::insertLine(bool moveCaret) indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); mDocument->insert(mCaretY, indentSpacesForRightLineText); nLinesInserted++; - mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), QStringList(), - SynSelectionMode::smNormal); + mUndoList->addChange(SynChangeReason::LineBreak, caretXY(), caretXY(), QStringList(), + SynSelectionMode::Normal); } //insert new line in middle of "{" and "}" if (notInComment && @@ -2522,8 +2504,8 @@ void SynEdit::insertLine(bool moveCaret) indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); mDocument->insert(mCaretY, indentSpacesForRightLineText); nLinesInserted++; - mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), QStringList(), - SynSelectionMode::smNormal); + mUndoList->addChange(SynChangeReason::LineBreak, caretXY(), caretXY(), QStringList(), + SynSelectionMode::Normal); } } if (moveCaret) @@ -2538,7 +2520,7 @@ void SynEdit::insertLine(bool moveCaret) void SynEdit::doTabKey() { - if (mActiveSelectionMode == SynSelectionMode::smColumn) { + if (mActiveSelectionMode == SynSelectionMode::Column) { doAddChar('\t'); return; } @@ -2549,9 +2531,9 @@ void SynEdit::doTabKey() } int i = 0; { - mUndoList->BeginBlock(); + mUndoList->beginBlock(); auto action = finally([this]{ - mUndoList->EndBlock(); + mUndoList->endBlock(); }); if (selAvail()) { setSelectedTextEmpty(); @@ -2631,25 +2613,25 @@ bool SynEdit::canDoBlockIndent() } - if (BB.Line > mDocument->count() || BE.Line > mDocument->count()) { + if (BB.line > mDocument->count() || BE.line > mDocument->count()) { return false; } - if (mActiveSelectionMode == SynSelectionMode::smNormal) { - QString s = mDocument->getString(BB.Line-1).mid(0,BB.Char-1); + if (mActiveSelectionMode == SynSelectionMode::Normal) { + QString s = mDocument->getString(BB.line-1).mid(0,BB.ch-1); if (!s.trimmed().isEmpty()) return false; - if (BE.Char>1) { - QString s1=mDocument->getString(BE.Line-1).mid(BE.Char-1); - QString s2=mDocument->getString(BE.Line-1).mid(0,BE.Char-1); + if (BE.ch>1) { + QString s1=mDocument->getString(BE.line-1).mid(BE.ch-1); + QString s2=mDocument->getString(BE.line-1).mid(0,BE.ch-1); if (!s1.trimmed().isEmpty() && !s2.trimmed().isEmpty()) return false; } } - if (mActiveSelectionMode == SynSelectionMode::smColumn) { - int startCol = charToColumn(BB.Line,BB.Char); - int endCol = charToColumn(BE.Line,BE.Char); - for (int i = BB.Line; i<=BE.Line;i++) { + if (mActiveSelectionMode == SynSelectionMode::Column) { + int startCol = charToColumn(BB.line,BB.ch); + int endCol = charToColumn(BE.line,BE.ch); + for (int i = BB.line; i<=BE.line;i++) { QString line = mDocument->getString(i-1); int startChar = columnToChar(i,startCol); QString s = line.mid(0,startChar-1); @@ -2675,9 +2657,9 @@ QRect SynEdit::calculateCaretRect() const coord.Column = charToColumn(sLine,mCaretX+mInputPreeditString.length()); } int rows=1; - if (mActiveSelectionMode == SynSelectionMode::smColumn) { - int startRow = lineToRow(std::min(blockBegin().Line, blockEnd().Line)); - int endRow = lineToRow(std::max(blockBegin().Line, blockEnd().Line)); + if (mActiveSelectionMode == SynSelectionMode::Column) { + int startRow = lineToRow(std::min(blockBegin().line, blockEnd().line)); + int endRow = lineToRow(std::max(blockBegin().line, blockEnd().line)); coord.Row = startRow; rows = endRow-startRow+1; } @@ -2686,7 +2668,7 @@ QRect SynEdit::calculateCaretRect() const if (mCaretY <= mDocument->count() && mCaretX <= mDocument->getString(mCaretY-1).length()) { caretWidth = charColumns(getDisplayStringAtLine(mCaretY)[mCaretX-1])*mCharWidth; } - if (mActiveSelectionMode == SynSelectionMode::smColumn) { + if (mActiveSelectionMode == SynSelectionMode::Column) { return QRect(caretPos.x(),caretPos.y(),caretWidth, mTextHeight*(rows)); } else { @@ -2719,6 +2701,7 @@ void SynEdit::computeCaret() int X=iMousePos.x(); int Y=iMousePos.y(); + BufferCoord oldCaret = caretXY(); DisplayCoord vCaretNearestPos = pixelsToNearestRowColumn(X, Y); vCaretNearestPos.Row = minMax(vCaretNearestPos.Row, 1, displayLineCount()); setInternalDisplayXY(vCaretNearestPos); @@ -2796,11 +2779,11 @@ void SynEdit::doBlockIndent() BE = caretXY(); } // build text to insert - if (BE.Char == 1 && BE.Line != BB.Line) { - e = BE.Line - 1; + if (BE.ch == 1 && BE.line != BB.line) { + e = BE.line - 1; x = 1; } else { - e = BE.Line; + e = BE.line; if (mOptions.testFlag(SynEditorOption::eoTabsToSpaces)) x = caretX() + tabWidth(); else @@ -2811,28 +2794,28 @@ void SynEdit::doBlockIndent() } else { spaces = "\t"; } - for (i = BB.Line; iBeginBlock(); - mUndoList->AddChange(SynChangeReason::crCaret, oldCaretPos, oldCaretPos,QStringList(), activeSelectionMode()); - mUndoList->AddChange(SynChangeReason::crSelection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode()); - insertionPos.Line = BB.Line; - if (mActiveSelectionMode == SynSelectionMode::smColumn) - insertionPos.Char = std::min(BB.Char, BE.Char); + mUndoList->beginBlock(); + mUndoList->addChange(SynChangeReason::Caret, oldCaretPos, oldCaretPos,QStringList(), activeSelectionMode()); + mUndoList->addChange(SynChangeReason::Selection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode()); + insertionPos.line = BB.line; + if (mActiveSelectionMode == SynSelectionMode::Column) + insertionPos.ch = std::min(BB.ch, BE.ch); else - insertionPos.Char = 1; + insertionPos.ch = 1; insertBlock(insertionPos, insertionPos, strToInsert); //adjust caret and selection - oldCaretPos.Char = x; - if (BB.Char > 1) - BB.Char += spaces.length(); - if (BE.Char > 1) - BE.Char+=spaces.length(); + oldCaretPos.ch = x; + if (BB.ch > 1) + BB.ch += spaces.length(); + if (BE.ch > 1) + BE.ch+=spaces.length(); setCaretAndSelection(oldCaretPos, BB, BE); - mUndoList->EndBlock(); + mUndoList->endBlock(); } void SynEdit::doBlockUnindent() @@ -2851,16 +2834,16 @@ void SynEdit::doBlockUnindent() } BufferCoord oldCaretPos = caretXY(); int x = 0; - mUndoList->BeginBlock(); - mUndoList->AddChange(SynChangeReason::crCaret, oldCaretPos, oldCaretPos,QStringList(), activeSelectionMode()); - mUndoList->AddChange(SynChangeReason::crSelection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode()); + mUndoList->beginBlock(); + mUndoList->addChange(SynChangeReason::Caret, oldCaretPos, oldCaretPos,QStringList(), activeSelectionMode()); + mUndoList->addChange(SynChangeReason::Selection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode()); - int e = BE.Line; + int e = BE.line; // convert selection to complete lines - if (BE.Char == 1) - e = BE.Line - 1; + if (BE.ch == 1) + e = BE.line - 1; // build string to delete - for (int i = BB.Line; i<= e;i++) { + for (int i = BB.line; i<= e;i++) { QString line = mDocument->getString(i - 1); if (line.isEmpty()) continue; @@ -2873,28 +2856,28 @@ void SynEdit::doBlockUnindent() charsToDelete++; if (charsToDelete == 0) charsToDelete = 1; - if (i==BB.Line) + if (i==BB.line) firstIndent = charsToDelete; if (i==e) lastIndent = charsToDelete; - if (i==oldCaretPos.Line) + if (i==oldCaretPos.line) x = charsToDelete; QString tempString = line.mid(charsToDelete); mDocument->putString(i-1,tempString); - mUndoList->AddChange(SynChangeReason::crDelete, + mUndoList->addChange(SynChangeReason::Delete, BufferCoord{1,i}, BufferCoord{charsToDelete+1,i}, QStringList(line.left(charsToDelete)), - SynSelectionMode::smNormal); + SynSelectionMode::Normal); } // restore selection //adjust the x position of orgcaretpos appropriately - oldCaretPos.Char -= x; - BB.Char -= firstIndent; - BE.Char -= lastIndent; + oldCaretPos.ch -= x; + BB.ch -= firstIndent; + BE.ch -= lastIndent; setCaretAndSelection(oldCaretPos, BB, BE); - mUndoList->EndBlock(); + mUndoList->endBlock(); } void SynEdit::doAddChar(QChar AChar) @@ -2907,18 +2890,18 @@ void SynEdit::doAddChar(QChar AChar) //mCaretX will change after setSelLength; if (mInserting == false && !selAvail()) { switch(mActiveSelectionMode) { - case SynSelectionMode::smColumn: { + case SynSelectionMode::Column: { //we can't use blockBegin()/blockEnd() BufferCoord start=mBlockBegin; BufferCoord end=mBlockEnd; - if (start.Line > end.Line ) + if (start.line > end.line ) std::swap(start,end); - start.Char++; // make sure we select a whole char in the start line + start.ch++; // make sure we select a whole char in the start line setBlockBegin(start); setBlockEnd(end); } break; - case SynSelectionMode::smLine: + case SynSelectionMode::Line: //do nothing; break; default: @@ -2930,7 +2913,7 @@ void SynEdit::doAddChar(QChar AChar) doSetSelText(AChar); } else if (AChar.isSpace()) { // break group undo chain - mUndoList->AddGroupBreak(); + mUndoList->addGroupBreak(); doSetSelText(AChar); // break group undo chain // if (mActiveSelectionMode!=SynSelectionMode::smColumn) @@ -2939,12 +2922,12 @@ void SynEdit::doAddChar(QChar AChar) // BufferCoord{0, 0}, // "", SynSelectionMode::smNormal); } else { - mUndoList->BeginBlock(); + mUndoList->beginBlock(); doSetSelText(AChar); int oldCaretX=mCaretX-1; int oldCaretY=mCaretY; // auto - if (mActiveSelectionMode==SynSelectionMode::smNormal + if (mActiveSelectionMode==SynSelectionMode::Normal && mOptions.testFlag(eoAutoIndent) && mHighlighter && mHighlighter->getClass()==SynHighlighterClass::CppHighlighter @@ -2961,19 +2944,19 @@ void SynEdit::doAddChar(QChar AChar) internalSetCaretXY(BufferCoord{newLine.length()+2,oldCaretY}); setBlockBegin(caretXY()); setBlockEnd(caretXY()); - mUndoList->AddChange( - SynChangeReason::crDelete, + mUndoList->addChange( + SynChangeReason::Delete, BufferCoord{1, oldCaretY}, BufferCoord{line.length()+1, oldCaretY}, QStringList(line), - SynSelectionMode::smNormal + SynSelectionMode::Normal ); - mUndoList->AddChange( - SynChangeReason::crInsert, + mUndoList->addChange( + SynChangeReason::Insert, BufferCoord{1, oldCaretY}, BufferCoord{newLine.length()+1, oldCaretY}, QStringList(), - SynSelectionMode::smNormal + SynSelectionMode::Normal ); } } @@ -2987,19 +2970,19 @@ void SynEdit::doAddChar(QChar AChar) internalSetCaretXY(BufferCoord{newLine.length()+2,oldCaretY}); setBlockBegin(caretXY()); setBlockEnd(caretXY()); - mUndoList->AddChange( - SynChangeReason::crDelete, + mUndoList->addChange( + SynChangeReason::Delete, BufferCoord{1, oldCaretY}, BufferCoord{line.length()+1, oldCaretY}, QStringList(line), - SynSelectionMode::smNormal + SynSelectionMode::Normal ); - mUndoList->AddChange( - SynChangeReason::crInsert, + mUndoList->addChange( + SynChangeReason::Insert, BufferCoord{1, oldCaretY}, BufferCoord{newLine.length()+1, oldCaretY}, QStringList(), - SynSelectionMode::smNormal + SynSelectionMode::Normal ); } } @@ -3017,26 +3000,26 @@ void SynEdit::doAddChar(QChar AChar) internalSetCaretXY(newCaretPos); setBlockBegin(caretXY()); setBlockEnd(caretXY()); - mUndoList->AddChange( - SynChangeReason::crDelete, + mUndoList->addChange( + SynChangeReason::Delete, BufferCoord{1, oldCaretY}, BufferCoord{left.length()+1, oldCaretY}, QStringList(left), - SynSelectionMode::smNormal + SynSelectionMode::Normal ); - mUndoList->AddChange( - SynChangeReason::crInsert, + mUndoList->addChange( + SynChangeReason::Insert, BufferCoord{1, oldCaretY}, BufferCoord{newLeft.length()+1, oldCaretY}, QStringList(""), - SynSelectionMode::smNormal + SynSelectionMode::Normal ); } } } } - mUndoList->EndBlock(); + mUndoList->endBlock(); } //DoOnPaintTransient(ttAfter); } @@ -3045,26 +3028,16 @@ void SynEdit::doCutToClipboard() { if (mReadOnly) return; - mUndoList->BeginBlock(); - mUndoList->AddChange( - SynChangeReason::crCaret, - caretXY(), - caretXY(), - QStringList(), - activeSelectionMode()); - mUndoList->AddChange( - SynChangeReason::crSelection, - mBlockBegin, - mBlockEnd, - QStringList(), - SynSelectionMode::smNormal); + mUndoList->beginBlock(); + addCaretToUndo(); + addSelectionToUndo(); if (!selAvail()) { doSelecteLine(); } internalDoCopyToClipboard(selText()); setSelectedTextEmpty(); - mUndoList->EndBlock(); - mUndoList->AddGroupBreak(); + mUndoList->endBlock(); + mUndoList->addGroupBreak(); } void SynEdit::doCopyToClipboard() @@ -3072,7 +3045,7 @@ void SynEdit::doCopyToClipboard() bool selected=selAvail(); if (!selected) doSelecteLine(); - bool ChangeTrim = (mActiveSelectionMode == SynSelectionMode::smColumn) && + bool ChangeTrim = (mActiveSelectionMode == SynSelectionMode::Column) && mOptions.testFlag(eoTrimTrailingSpaces); QString sText; { @@ -3107,7 +3080,7 @@ void SynEdit::doPasteFromClipboard() if (text.isEmpty()) return; doOnPaintTransient(SynTransientType::ttBefore); - mUndoList->BeginBlock(); + mUndoList->beginBlock(); // if (selAvail()) { // mUndoList->AddChange( // SynChangeReason::crDelete, @@ -3124,7 +3097,7 @@ void SynEdit::doPasteFromClipboard() mBlockEnd = vEndOfBlock; qDebug()<EndBlock(); + mUndoList->endBlock(); } void SynEdit::incPaintLock() @@ -3240,7 +3213,6 @@ void SynEdit::setInternalDisplayXY(const DisplayCoord &aPos) incPaintLock(); internalSetCaretXY(displayToBufferPos(aPos)); decPaintLock(); - updateLastCaretX(); } void SynEdit::internalSetCaretXY(const BufferCoord &Value) @@ -3278,7 +3250,7 @@ void SynEdit::doOnStatusChange(SynStatusChanges) void SynEdit::insertBlock(const BufferCoord& startPos, const BufferCoord& endPos, const QStringList& blockText) { setCaretAndSelection(startPos, startPos, startPos); - setSelTextPrimitiveEx(SynSelectionMode::smColumn, blockText); + setSelTextPrimitiveEx(SynSelectionMode::Column, blockText); } void SynEdit::updateScrollbars() @@ -4296,18 +4268,18 @@ void SynEdit::doAddStr(const QString &s) { if (mInserting == false && !selAvail()) { switch(mActiveSelectionMode) { - case SynSelectionMode::smColumn: { + case SynSelectionMode::Column: { //we can't use blockBegin()/blockEnd() BufferCoord start=blockBegin(); BufferCoord end=blockEnd(); - if (start.Line > end.Line ) + if (start.line > end.line ) std::swap(start,end); - start.Char+=s.length(); // make sure we select a whole char in the start line + start.ch+=s.length(); // make sure we select a whole char in the start line setBlockBegin(start); setBlockEnd(end); } break; - case SynSelectionMode::smLine: + case SynSelectionMode::Line: //do nothing; break; default: @@ -4323,49 +4295,49 @@ void SynEdit::doUndo() return; //Remove Group Break; - if (mUndoList->LastChangeReason() == SynChangeReason::crGroupBreak) { + if (mUndoList->lastChangeReason() == SynChangeReason::GroupBreak) { int OldBlockNumber = mRedoList->blockChangeNumber(); auto action = finally([&,this]{ mRedoList->setBlockChangeNumber(OldBlockNumber); }); - PSynEditUndoItem Item = mUndoList->PopItem(); - mRedoList->setBlockChangeNumber(Item->changeNumber()); - mRedoList->AddGroupBreak(); + PSynEditUndoItem item = mUndoList->popItem(); + mRedoList->setBlockChangeNumber(item->changeNumber()); + mRedoList->addGroupBreak(); } - PSynEditUndoItem Item = mUndoList->PeekItem(); - if (Item) { - int OldChangeNumber = Item->changeNumber(); - int SaveChangeNumber = mRedoList->blockChangeNumber(); - mRedoList->setBlockChangeNumber(Item->changeNumber()); + PSynEditUndoItem item = mUndoList->peekItem(); + if (item) { + int oldChangeNumber = item->changeNumber(); + int saveChangeNumber = mRedoList->blockChangeNumber(); + mRedoList->setBlockChangeNumber(item->changeNumber()); { auto action = finally([&,this] { - mRedoList->setBlockChangeNumber(SaveChangeNumber); + mRedoList->setBlockChangeNumber(saveChangeNumber); }); //skip group chain breakers - if (mUndoList->LastChangeReason()==SynChangeReason::crGroupBreak) { - while (!mUndoList->isEmpty() && mUndoList->LastChangeReason()==SynChangeReason::crGroupBreak) { + if (mUndoList->lastChangeReason()==SynChangeReason::GroupBreak) { + while (!mUndoList->isEmpty() && mUndoList->lastChangeReason()==SynChangeReason::GroupBreak) { doUndoItem(); } } - SynChangeReason FLastChange = mUndoList->LastChangeReason(); - bool FKeepGoing; + SynChangeReason lastChange = mUndoList->lastChangeReason(); + bool keepGoing; do { doUndoItem(); - Item = mUndoList->PeekItem(); - if (!Item) - FKeepGoing = false; + item = mUndoList->peekItem(); + if (!item) + keepGoing = false; else { - if (Item->changeNumber() == OldChangeNumber) - FKeepGoing = true; + if (item->changeNumber() == oldChangeNumber) + keepGoing = true; else { - FKeepGoing = (mOptions.testFlag(eoGroupUndo) && - (FLastChange == Item->changeReason()) ); + keepGoing = (mOptions.testFlag(eoGroupUndo) && + (lastChange == item->changeReason()) ); } - OldChangeNumber=Item->changeNumber(); - FLastChange = Item->changeReason(); + oldChangeNumber=item->changeNumber(); + lastChange = item->changeReason(); } - } while (FKeepGoing); + } while (keepGoing); } } } @@ -4375,9 +4347,9 @@ void SynEdit::doUndoItem() mUndoing = true; bool ChangeScrollPastEol = ! mOptions.testFlag(eoScrollPastEol); - PSynEditUndoItem Item = mUndoList->PopItem(); - if (Item) { - setActiveSelectionMode(Item->changeSelMode()); + PSynEditUndoItem item = mUndoList->popItem(); + if (item) { + setActiveSelectionMode(item->changeSelMode()); incPaintLock(); auto action = finally([&,this]{ mUndoing = false; @@ -4386,97 +4358,97 @@ void SynEdit::doUndoItem() decPaintLock(); }); mOptions.setFlag(eoScrollPastEol); - switch(Item->changeReason()) { - case SynChangeReason::crCaret: - mRedoList->AddChange( - Item->changeReason(), + switch(item->changeReason()) { + case SynChangeReason::Caret: + mRedoList->addChange( + item->changeReason(), caretXY(), caretXY(), QStringList(), - Item->changeSelMode()); - internalSetCaretXY(Item->changeStartPos()); + item->changeSelMode()); + internalSetCaretXY(item->changeStartPos()); break; - case SynChangeReason::crLeftTop: + case SynChangeReason::LeftTop: BufferCoord p; - p.Char = leftChar(); - p.Line = topLine(); - mRedoList->AddChange( - Item->changeReason(), + p.ch = leftChar(); + p.line = topLine(); + mRedoList->addChange( + item->changeReason(), p, p, QStringList(), - Item->changeSelMode()); - setLeftChar(Item->changeStartPos().Char); - setTopLine(Item->changeStartPos().Line); + item->changeSelMode()); + setLeftChar(item->changeStartPos().ch); + setTopLine(item->changeStartPos().line); break; - case SynChangeReason::crSelection: - mRedoList->AddChange( - Item->changeReason(), + case SynChangeReason::Selection: + mRedoList->addChange( + item->changeReason(), mBlockBegin, mBlockEnd, QStringList(), - Item->changeSelMode()); - setCaretAndSelection(caretXY(), Item->changeStartPos(), Item->changeEndPos()); + item->changeSelMode()); + setCaretAndSelection(caretXY(), item->changeStartPos(), item->changeEndPos()); break; - case SynChangeReason::crInsert: { - QStringList tmpText = getContent(Item->changeStartPos(),Item->changeEndPos(),Item->changeSelMode()); - doDeleteText(Item->changeStartPos(),Item->changeEndPos(),Item->changeSelMode()); - mRedoList->AddChange( - Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), + case SynChangeReason::Insert: { + QStringList tmpText = getContent(item->changeStartPos(),item->changeEndPos(),item->changeSelMode()); + doDeleteText(item->changeStartPos(),item->changeEndPos(),item->changeSelMode()); + mRedoList->addChange( + item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), tmpText, - Item->changeSelMode()); - internalSetCaretXY(Item->changeStartPos()); + item->changeSelMode()); + internalSetCaretXY(item->changeStartPos()); break; } - case SynChangeReason::crMoveSelectionUp: - setBlockBegin(BufferCoord{Item->changeStartPos().Char, Item->changeStartPos().Line-1}); - setBlockEnd(BufferCoord{Item->changeEndPos().Char, Item->changeEndPos().Line-1}); + case SynChangeReason::MoveSelectionUp: + setBlockBegin(BufferCoord{item->changeStartPos().ch, item->changeStartPos().line-1}); + setBlockEnd(BufferCoord{item->changeEndPos().ch, item->changeEndPos().line-1}); doMoveSelDown(); - mRedoList->AddChange( - Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), - Item->changeText(), - Item->changeSelMode()); + mRedoList->addChange( + item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), + item->changeText(), + item->changeSelMode()); break; - case SynChangeReason::crMoveSelectionDown: - setBlockBegin(BufferCoord{Item->changeStartPos().Char, Item->changeStartPos().Line+1}); - setBlockEnd(BufferCoord{Item->changeEndPos().Char, Item->changeEndPos().Line+1}); + case SynChangeReason::MoveSelectionDown: + setBlockBegin(BufferCoord{item->changeStartPos().ch, item->changeStartPos().line+1}); + setBlockEnd(BufferCoord{item->changeEndPos().ch, item->changeEndPos().line+1}); doMoveSelUp(); - mRedoList->AddChange( - Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), - Item->changeText(), - Item->changeSelMode()); + mRedoList->addChange( + item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), + item->changeText(), + item->changeSelMode()); break; - case SynChangeReason::crDelete: { + case SynChangeReason::Delete: { // If there's no selection, we have to set // the Caret's position manualy. // qDebug()<<"undo delete"; // qDebug()<changeText(); // qDebug()<changeStartPos().Line<changeStartPos().Char; - doInsertText(Item->changeStartPos(),Item->changeText(),Item->changeSelMode(), - Item->changeStartPos().Line, - Item->changeEndPos().Line); - internalSetCaretXY(Item->changeEndPos()); - mRedoList->AddChange( - Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), - Item->changeText(), - Item->changeSelMode()); + doInsertText(item->changeStartPos(),item->changeText(),item->changeSelMode(), + item->changeStartPos().line, + item->changeEndPos().line); + internalSetCaretXY(item->changeEndPos()); + mRedoList->addChange( + item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), + item->changeText(), + item->changeSelMode()); ensureCursorPosVisible(); break; } - case SynChangeReason::crLineBreak:{ + case SynChangeReason::LineBreak:{ QString s; - if (!Item->changeText().isEmpty()) { - s=Item->changeText()[0]; + if (!item->changeText().isEmpty()) { + s=item->changeText()[0]; } // If there's no selection, we have to set // the Caret's position manualy. - internalSetCaretXY(Item->changeStartPos()); + internalSetCaretXY(item->changeStartPos()); if (mCaretY > 0) { QString TmpStr = mDocument->getString(mCaretY - 1); if ( (mCaretX > TmpStr.length() + 1) && (leftSpaces(s) == 0)) @@ -4485,12 +4457,12 @@ void SynEdit::doUndoItem() mDocument->deleteAt(mCaretY); doLinesDeleted(mCaretY, 1); } - mRedoList->AddChange( - Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), - Item->changeText(), - Item->changeSelMode()); + mRedoList->addChange( + item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), + item->changeText(), + item->changeSelMode()); break; } default: @@ -4504,52 +4476,52 @@ void SynEdit::doRedo() if (mReadOnly) return; - PSynEditUndoItem Item = mRedoList->PeekItem(); - if (!Item) + PSynEditUndoItem item = mRedoList->peekItem(); + if (!item) return; - int OldChangeNumber = Item->changeNumber(); - int SaveChangeNumber = mUndoList->blockChangeNumber(); - mUndoList->setBlockChangeNumber(Item->changeNumber()); + int oldChangeNumber = item->changeNumber(); + int saveChangeNumber = mUndoList->blockChangeNumber(); + mUndoList->setBlockChangeNumber(item->changeNumber()); { auto action = finally([&,this]{ - mUndoList->setBlockChangeNumber(SaveChangeNumber); + mUndoList->setBlockChangeNumber(saveChangeNumber); }); //skip group chain breakers - if (mRedoList->LastChangeReason()==SynChangeReason::crGroupBreak) { - while (!mRedoList->isEmpty() && mRedoList->LastChangeReason()==SynChangeReason::crGroupBreak) { + if (mRedoList->lastChangeReason()==SynChangeReason::GroupBreak) { + while (!mRedoList->isEmpty() && mRedoList->lastChangeReason()==SynChangeReason::GroupBreak) { doRedoItem(); } } - SynChangeReason FLastChange = mRedoList->LastChangeReason(); - bool FKeepGoing; + SynChangeReason lastChange = mRedoList->lastChangeReason(); + bool keepGoing; do { doRedoItem(); - Item = mRedoList->PeekItem(); - if (!Item) - FKeepGoing = false; + item = mRedoList->peekItem(); + if (!item) + keepGoing = false; else { - if (Item->changeNumber() == OldChangeNumber) - FKeepGoing = true; + if (item->changeNumber() == oldChangeNumber) + keepGoing = true; else { - FKeepGoing = (mOptions.testFlag(eoGroupUndo) && - (FLastChange == Item->changeReason())); + keepGoing = (mOptions.testFlag(eoGroupUndo) && + (lastChange == item->changeReason())); } - OldChangeNumber=Item->changeNumber(); - FLastChange = Item->changeReason(); + oldChangeNumber=item->changeNumber(); + lastChange = item->changeReason(); } - } while (FKeepGoing); + } while (keepGoing); } //Remove Group Break - if (mRedoList->LastChangeReason() == SynChangeReason::crGroupBreak) { + if (mRedoList->lastChangeReason() == SynChangeReason::GroupBreak) { int OldBlockNumber = mUndoList->blockChangeNumber(); - Item = mRedoList->PopItem(); + item = mRedoList->popItem(); { auto action2=finally([&,this]{ mUndoList->setBlockChangeNumber(OldBlockNumber); }); - mUndoList->setBlockChangeNumber(Item->changeNumber()); - mUndoList->AddGroupBreak(); + mUndoList->setBlockChangeNumber(item->changeNumber()); + mUndoList->addGroupBreak(); } updateModifiedStatus(); } @@ -4559,9 +4531,9 @@ void SynEdit::doRedoItem() { mUndoing = true; bool ChangeScrollPastEol = ! mOptions.testFlag(eoScrollPastEol); - PSynEditUndoItem Item = mRedoList->PopItem(); - if (Item) { - setActiveSelectionMode(Item->changeSelMode()); + PSynEditUndoItem item = mRedoList->popItem(); + if (item) { + setActiveSelectionMode(item->changeSelMode()); incPaintLock(); mOptions.setFlag(eoScrollPastEol); mUndoList->setInsideRedo(true); @@ -4572,90 +4544,90 @@ void SynEdit::doRedoItem() mOptions.setFlag(eoScrollPastEol,false); decPaintLock(); }); - switch(Item->changeReason()) { - case SynChangeReason::crCaret: - mUndoList->AddChange( - Item->changeReason(), + switch(item->changeReason()) { + case SynChangeReason::Caret: + mUndoList->addChange( + item->changeReason(), caretXY(), caretXY(), QStringList(), mActiveSelectionMode); - internalSetCaretXY(Item->changeStartPos()); + internalSetCaretXY(item->changeStartPos()); break; - case SynChangeReason::crLeftTop: + case SynChangeReason::LeftTop: BufferCoord p; - p.Char = leftChar(); - p.Line = topLine(); - mUndoList->AddChange( - Item->changeReason(), + p.ch = leftChar(); + p.line = topLine(); + mUndoList->addChange( + item->changeReason(), p, p, QStringList(), - Item->changeSelMode()); - setLeftChar(Item->changeStartPos().Char); - setTopLine(Item->changeStartPos().Line); + item->changeSelMode()); + setLeftChar(item->changeStartPos().ch); + setTopLine(item->changeStartPos().line); break; - case SynChangeReason::crSelection: - mUndoList->AddChange( - Item->changeReason(), + case SynChangeReason::Selection: + mUndoList->addChange( + item->changeReason(), mBlockBegin, mBlockEnd, QStringList(), mActiveSelectionMode); setCaretAndSelection( caretXY(), - Item->changeStartPos(), - Item->changeEndPos()); + item->changeStartPos(), + item->changeEndPos()); break; - case SynChangeReason::crMoveSelectionUp: - setBlockBegin(BufferCoord{Item->changeStartPos().Char, Item->changeStartPos().Line}); - setBlockEnd(BufferCoord{Item->changeEndPos().Char, Item->changeEndPos().Line}); + case SynChangeReason::MoveSelectionUp: + setBlockBegin(BufferCoord{item->changeStartPos().ch, item->changeStartPos().line}); + setBlockEnd(BufferCoord{item->changeEndPos().ch, item->changeEndPos().line}); doMoveSelUp(); - mUndoList->AddChange( - Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), - Item->changeText(), - Item->changeSelMode()); + mUndoList->addChange( + item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), + item->changeText(), + item->changeSelMode()); break; - case SynChangeReason::crMoveSelectionDown: - setBlockBegin(BufferCoord{Item->changeStartPos().Char, Item->changeStartPos().Line}); - setBlockEnd(BufferCoord{Item->changeEndPos().Char, Item->changeEndPos().Line}); + case SynChangeReason::MoveSelectionDown: + setBlockBegin(BufferCoord{item->changeStartPos().ch, item->changeStartPos().line}); + setBlockEnd(BufferCoord{item->changeEndPos().ch, item->changeEndPos().line}); doMoveSelDown(); - mUndoList->AddChange( - Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), - Item->changeText(), - Item->changeSelMode()); + mUndoList->addChange( + item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), + item->changeText(), + item->changeSelMode()); break; - case SynChangeReason::crInsert: + case SynChangeReason::Insert: setCaretAndSelection( - Item->changeStartPos(), - Item->changeStartPos(), - Item->changeStartPos()); - doInsertText(Item->changeStartPos(),Item->changeText(), Item->changeSelMode(), - Item->changeStartPos().Line, - Item->changeEndPos().Line); - internalSetCaretXY(Item->changeEndPos()); - mUndoList->AddChange(Item->changeReason(), - Item->changeStartPos(), - Item->changeEndPos(), + item->changeStartPos(), + item->changeStartPos(), + item->changeStartPos()); + doInsertText(item->changeStartPos(),item->changeText(), item->changeSelMode(), + item->changeStartPos().line, + item->changeEndPos().line); + internalSetCaretXY(item->changeEndPos()); + mUndoList->addChange(item->changeReason(), + item->changeStartPos(), + item->changeEndPos(), QStringList(), - Item->changeSelMode()); + item->changeSelMode()); break; - case SynChangeReason::crDelete: { - doDeleteText(Item->changeStartPos(),Item->changeEndPos(),Item->changeSelMode()); - mUndoList->AddChange(Item->changeReason(), Item->changeStartPos(), - Item->changeEndPos(),Item->changeText(), - Item->changeSelMode()); - internalSetCaretXY(Item->changeStartPos()); + case SynChangeReason::Delete: { + doDeleteText(item->changeStartPos(),item->changeEndPos(),item->changeSelMode()); + mUndoList->addChange(item->changeReason(), item->changeStartPos(), + item->changeEndPos(),item->changeText(), + item->changeSelMode()); + internalSetCaretXY(item->changeStartPos()); break; }; - case SynChangeReason::crLineBreak: { - BufferCoord CaretPt = Item->changeStartPos(); - mUndoList->AddChange(Item->changeReason(), Item->changeStartPos(), - Item->changeEndPos(),Item->changeText(), - Item->changeSelMode()); + case SynChangeReason::LineBreak: { + BufferCoord CaretPt = item->changeStartPos(); + mUndoList->addChange(item->changeReason(), item->changeStartPos(), + item->changeEndPos(),item->changeText(), + item->changeSelMode()); setCaretAndSelection(CaretPt, CaretPt, CaretPt); commandProcessor(SynEditorCommand::ecLineBreak); break; @@ -4704,15 +4676,15 @@ QString SynEdit::selText() if (!selAvail()) { return ""; } else { - int ColFrom = blockBegin().Char; - int First = blockBegin().Line - 1; + int ColFrom = blockBegin().ch; + int First = blockBegin().line - 1; // - int ColTo = blockEnd().Char; - int Last = blockEnd().Line - 1; + int ColTo = blockEnd().ch; + int Last = blockEnd().line - 1; switch(mActiveSelectionMode) { - case SynSelectionMode::smNormal:{ - PSynEditFoldRange foldRange = foldStartAtLine(blockEnd().Line); + case SynSelectionMode::Normal:{ + PSynEditFoldRange foldRange = foldStartAtLine(blockEnd().line); QString s = mDocument->getString(Last); if ((foldRange) && foldRange->collapsed && ColTo>s.length()) { s=s+highlighter()->foldString(); @@ -4734,12 +4706,12 @@ QString SynEdit::selText() return result; } } - case SynSelectionMode::smColumn: + case SynSelectionMode::Column: { - First = blockBegin().Line; - ColFrom = charToColumn(blockBegin().Line, blockBegin().Char); - Last = blockEnd().Line; - ColTo = charToColumn(blockEnd().Line, blockEnd().Char); + First = blockBegin().line; + ColFrom = charToColumn(blockBegin().line, blockBegin().ch); + Last = blockEnd().line; + ColTo = charToColumn(blockEnd().line, blockEnd().ch); if (ColFrom > ColTo) std::swap(ColFrom, ColTo); if (First>Last) @@ -4755,7 +4727,7 @@ QString SynEdit::selText() } return result; } - case SynSelectionMode::smLine: + case SynSelectionMode::Line: { QString result; // If block selection includes LastLine, @@ -4783,15 +4755,15 @@ QStringList SynEdit::getContent(BufferCoord startPos, BufferCoord endPos, SynSel if (startPos>endPos) { std::swap(startPos,endPos); } - int ColFrom = startPos.Char; - int First = startPos.Line - 1; + int ColFrom = startPos.ch; + int First = startPos.line - 1; // - int ColTo = endPos.Char; - int Last = endPos.Line - 1; + int ColTo = endPos.ch; + int Last = endPos.line - 1; switch(mode) { - case SynSelectionMode::smNormal:{ - PSynEditFoldRange foldRange = foldStartAtLine(endPos.Line); + case SynSelectionMode::Normal:{ + PSynEditFoldRange foldRange = foldStartAtLine(endPos.line); QString s = mDocument->getString(Last); if ((foldRange) && foldRange->collapsed && ColTo>s.length()) { s=s+highlighter()->foldString(); @@ -4811,11 +4783,11 @@ QStringList SynEdit::getContent(BufferCoord startPos, BufferCoord endPos, SynSel result.append(mDocument->getString(Last).left(ColTo-1)); } break; - case SynSelectionMode::smColumn: - First = blockBegin().Line; - ColFrom = charToColumn(blockBegin().Line, blockBegin().Char); - Last = blockEnd().Line; - ColTo = charToColumn(blockEnd().Line, blockEnd().Char); + case SynSelectionMode::Column: + First = blockBegin().line; + ColFrom = charToColumn(blockBegin().line, blockBegin().ch); + Last = blockEnd().line; + ColTo = charToColumn(blockEnd().line, blockEnd().ch); if (ColFrom > ColTo) std::swap(ColFrom, ColTo); if (First>Last) @@ -4827,7 +4799,7 @@ QStringList SynEdit::getContent(BufferCoord startPos, BufferCoord endPos, SynSel result.append(s.mid(l-1,r-l)); } break; - case SynSelectionMode::smLine: + case SynSelectionMode::Line: // If block selection includes LastLine, // line break code(s) of the last line will not be added. for (int i= First; i<=Last - 1;i++) { @@ -4941,43 +4913,43 @@ void SynEdit::moveCaretHorz(int DX, bool isSelection) // only moving or selecting one char can change the line //bool bChangeY = !mOptions.testFlag(SynEditorOption::eoScrollPastEol); bool bChangeY=true; - if (bChangeY && (DX == -1) && (ptO.Char == 1) && (ptO.Line > 1)) { + if (bChangeY && (DX == -1) && (ptO.ch == 1) && (ptO.line > 1)) { // end of previous line - if (mActiveSelectionMode==SynSelectionMode::smColumn) { + if (mActiveSelectionMode==SynSelectionMode::Column) { return; } - int row = lineToRow(ptDst.Line); + int row = lineToRow(ptDst.line); row--; int line = rowToLine(row); - if (line!=ptDst.Line && line>=1) { - ptDst.Line = line; - ptDst.Char = getDisplayStringAtLine(ptDst.Line).length() + 1; + if (line!=ptDst.line && line>=1) { + ptDst.line = line; + ptDst.ch = getDisplayStringAtLine(ptDst.line).length() + 1; } - } else if (bChangeY && (DX == 1) && (ptO.Char > nLineLen) && (ptO.Line < mDocument->count())) { + } else if (bChangeY && (DX == 1) && (ptO.ch > nLineLen) && (ptO.line < mDocument->count())) { // start of next line - if (mActiveSelectionMode==SynSelectionMode::smColumn) { + if (mActiveSelectionMode==SynSelectionMode::Column) { return; } - int row = lineToRow(ptDst.Line); + int row = lineToRow(ptDst.line); row++; int line = rowToLine(row); // qDebug()<count()) { - ptDst.Line = line; - ptDst.Char = 1; + if (line!=ptDst.line && line<=mDocument->count()) { + ptDst.line = line; + ptDst.ch = 1; } } else { - ptDst.Char = std::max(1, ptDst.Char + DX); + ptDst.ch = std::max(1, ptDst.ch + DX); // don't go past last char when ScrollPastEol option not set if ((DX > 0) && bChangeY) - ptDst.Char = std::min(ptDst.Char, nLineLen + 1); + ptDst.ch = std::min(ptDst.ch, nLineLen + 1); } // set caret and block begin / end incPaintLock(); if (mOptions.testFlag(eoAltSetsColumnMode) && - (mActiveSelectionMode != SynSelectionMode::smLine)) { + (mActiveSelectionMode != SynSelectionMode::Line)) { if (qApp->keyboardModifiers().testFlag(Qt::AltModifier)) { - setActiveSelectionMode(SynSelectionMode::smColumn); + setActiveSelectionMode(SynSelectionMode::Column); } else setActiveSelectionMode(selectionMode()); } @@ -5006,8 +4978,8 @@ void SynEdit::moveCaretVert(int DY, bool isSelection) } BufferCoord vDstLineChar = displayToBufferPos(ptDst); - if (mActiveSelectionMode==SynSelectionMode::smColumn) { - QString s=mDocument->getString(vDstLineChar.Line-1); + if (mActiveSelectionMode==SynSelectionMode::Column) { + QString s=mDocument->getString(vDstLineChar.line-1); int cols=stringColumns(s,0); if (cols+1keyboardModifiers().testFlag(Qt::AltModifier)) - setActiveSelectionMode(SynSelectionMode::smColumn); + setActiveSelectionMode(SynSelectionMode::Column); else setActiveSelectionMode(selectionMode()); } @@ -5035,12 +5007,12 @@ void SynEdit::moveCaretVert(int DY, bool isSelection) void SynEdit::moveCaretAndSelection(const BufferCoord &ptBefore, const BufferCoord &ptAfter, bool isSelection) { - if (mOptions.testFlag(SynEditorOption::eoGroupUndo) && mUndoList->CanUndo()) - mUndoList->AddGroupBreak(); + if (mOptions.testFlag(SynEditorOption::eoGroupUndo)) { + mUndoList->addGroupBreak(); + } incPaintLock(); if (isSelection) { - if (!selAvail()) setBlockBegin(ptBefore); setBlockEnd(ptAfter); @@ -5116,13 +5088,13 @@ void SynEdit::setSelTextPrimitiveEx(SynSelectionMode mode, const QStringList &te BufferCoord endPos = blockEnd(); if (selAvail()) { if (!mUndoing && !text.isEmpty()) { - mUndoList->BeginBlock(); + mUndoList->beginBlock(); groupUndo=true; } doDeleteText(startPos,endPos,activeSelectionMode()); - if (mode == SynSelectionMode::smColumn) { - int colBegin = charToColumn(startPos.Line,startPos.Char); - int colEnd = charToColumn(endPos.Line,endPos.Char); + if (mode == SynSelectionMode::Column) { + int colBegin = charToColumn(startPos.line,startPos.ch); + int colEnd = charToColumn(endPos.line,endPos.ch); if (colBeginEndBlock(); + mUndoList->endBlock(); } decPaintLock(); setStatusChanged(SynStatusChange::scSelection); @@ -5145,10 +5117,10 @@ void SynEdit::doSetSelText(const QString &value) bool blockBeginned = false; auto action = finally([this, &blockBeginned]{ if (blockBeginned) - mUndoList->EndBlock(); + mUndoList->endBlock(); }); if (selAvail()) { - mUndoList->BeginBlock(); + mUndoList->beginBlock(); blockBeginned = true; // mUndoList->AddChange( // SynChangeReason::crDelete, mBlockBegin, mBlockEnd, @@ -5187,13 +5159,13 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS ptStart = blockBegin(); ptEnd = blockEnd(); // search the whole line in the line selection mode - if (mActiveSelectionMode == SynSelectionMode::smLine) { - ptStart.Char = 1; - ptEnd.Char = mDocument->getString(ptEnd.Line - 1).length(); - } else if (mActiveSelectionMode == SynSelectionMode::smColumn) { + if (mActiveSelectionMode == SynSelectionMode::Line) { + ptStart.ch = 1; + ptEnd.ch = mDocument->getString(ptEnd.line - 1).length(); + } else if (mActiveSelectionMode == SynSelectionMode::Column) { // make sure the start column is smaller than the end column - if (ptStart.Char > ptEnd.Char) - std::swap(ptStart.Char,ptEnd.Char); + if (ptStart.ch > ptEnd.ch) + std::swap(ptStart.ch,ptEnd.ch); } // ignore the cursor position when searching in the selection if (bBackward) { @@ -5202,10 +5174,10 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS ptCurrent = ptStart; } } else { - ptStart.Char = 1; - ptStart.Line = 1; - ptEnd.Line = mDocument->count(); - ptEnd.Char = mDocument->getString(ptEnd.Line - 1).length(); + ptStart.ch = 1; + ptStart.line = 1; + ptEnd.line = mDocument->count(); + ptEnd.ch = mDocument->getString(ptEnd.line - 1).length(); if (bFromCursor) { if (bBackward) ptEnd = caretXY(); @@ -5228,15 +5200,15 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS auto action = finally([&,this]{ if (dobatchReplace) { decPaintLock(); - mUndoList->EndBlock(); + mUndoList->endBlock(); } doOnPaintTransient(SynTransientType::ttAfter); }); int i; // If it's a search only we can leave the procedure now. SynSearchAction searchAction = SynSearchAction::Exit; - while ((ptCurrent.Line >= ptStart.Line) && (ptCurrent.Line <= ptEnd.Line)) { - int nInLine = searchEngine->findAll(mDocument->getString(ptCurrent.Line - 1)); + while ((ptCurrent.line >= ptStart.line) && (ptCurrent.line <= ptEnd.line)) { + int nInLine = searchEngine->findAll(mDocument->getString(ptCurrent.line - 1)); int iResultOffset = 0; if (bBackward) i = searchEngine->resultCount()-1; @@ -5257,28 +5229,28 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS bool isInValidSearchRange = true; int first = nFound; int last = nFound + nSearchLen; - if ((mActiveSelectionMode == SynSelectionMode::smNormal) + if ((mActiveSelectionMode == SynSelectionMode::Normal) || !sOptions.testFlag(ssoSelectedOnly)) { - if (((ptCurrent.Line == ptStart.Line) && (first < ptStart.Char)) || - ((ptCurrent.Line == ptEnd.Line) && (last > ptEnd.Char))) + if (((ptCurrent.line == ptStart.line) && (first < ptStart.ch)) || + ((ptCurrent.line == ptEnd.line) && (last > ptEnd.ch))) isInValidSearchRange = false; - } else if (mActiveSelectionMode == SynSelectionMode::smColumn) { + } else if (mActiveSelectionMode == SynSelectionMode::Column) { // solves bug in search/replace when smColumn mode active and no selection - isInValidSearchRange = ((first >= ptStart.Char) && (last <= ptEnd.Char)) - || (ptEnd.Char - ptStart.Char < 1); + isInValidSearchRange = ((first >= ptStart.ch) && (last <= ptEnd.ch)) + || (ptEnd.ch - ptStart.ch < 1); } if (!isInValidSearchRange) continue; result++; // Select the text, so the user can see it in the OnReplaceText event // handler or as the search result. - ptCurrent.Char = nFound; + ptCurrent.ch = nFound; setBlockBegin(ptCurrent); //Be sure to use the Ex version of CursorPos so that it appears in the middle if necessary - setCaretXYEx(false, BufferCoord{1, ptCurrent.Line}); + setCaretXYEx(false, BufferCoord{1, ptCurrent.line}); ensureCursorPosVisibleEx(true); - ptCurrent.Char += nSearchLen; + ptCurrent.ch += nSearchLen; setBlockEnd(ptCurrent); //internalSetCaretXY(ptCurrent); if (bBackward) @@ -5288,7 +5260,7 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS QString replaceText = searchEngine->replace(selText(), sReplace); if (matchedCallback && !dobatchReplace) { - searchAction = matchedCallback(sSearch,replaceText,ptCurrent.Line, + searchAction = matchedCallback(sSearch,replaceText,ptCurrent.line, nFound,nSearchLen); } if (searchAction==SynSearchAction::Exit) { @@ -5300,7 +5272,7 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS if (!dobatchReplace && (searchAction == SynSearchAction::ReplaceAll) ){ incPaintLock(); - mUndoList->BeginBlock(); + mUndoList->beginBlock(); dobatchReplace = true; } bool oldAutoIndent = mOptions.testFlag(SynEditorOption::eoAutoIndent); @@ -5312,8 +5284,8 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS internalSetCaretX(nFound + nReplaceLen); if ((nSearchLen != nReplaceLen)) { iResultOffset += nReplaceLen - nSearchLen; - if ((mActiveSelectionMode != SynSelectionMode::smColumn) && (caretY() == ptEnd.Line)) { - ptEnd.Char+=nReplaceLen - nSearchLen; + if ((mActiveSelectionMode != SynSelectionMode::Column) && (caretY() == ptEnd.line)) { + ptEnd.ch+=nReplaceLen - nSearchLen; setBlockEnd(ptEnd); } } @@ -5323,19 +5295,19 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS } // search next / previous line if (bBackward) - ptCurrent.Line--; + ptCurrent.line--; else - ptCurrent.Line++; - if (((ptCurrent.Line < ptStart.Line) || (ptCurrent.Line > ptEnd.Line)) + ptCurrent.line++; + if (((ptCurrent.line < ptStart.line) || (ptCurrent.line > ptEnd.line)) && bFromCursor && sOptions.testFlag(ssoWrapAround)){ if (confirmAroundCallback && !confirmAroundCallback()) break; //search start from cursor, search has finished but no result founds bFromCursor = false; - ptStart.Char = 1; - ptStart.Line = 1; - ptEnd.Line = mDocument->count(); - ptEnd.Char = mDocument->getString(ptEnd.Line - 1).length(); + ptStart.ch = 1; + ptStart.line = 1; + ptEnd.line = mDocument->count(); + ptEnd.ch = mDocument->getString(ptEnd.line - 1).length(); if (bBackward) { ptStart = originCaretXY; ptCurrent = ptEnd; @@ -5394,16 +5366,16 @@ void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SynSelectio { bool UpdateMarks = false; int MarkOffset = 0; - if (mode == SynSelectionMode::smNormal) { - PSynEditFoldRange foldRange = foldStartAtLine(endPos.Line); - QString s = mDocument->getString(endPos.Line-1); - if ((foldRange) && foldRange->collapsed && endPos.Char>s.length()) { + if (mode == SynSelectionMode::Normal) { + PSynEditFoldRange foldRange = foldStartAtLine(endPos.line); + QString s = mDocument->getString(endPos.line-1); + if ((foldRange) && foldRange->collapsed && endPos.ch>s.length()) { QString newS=s+highlighter()->foldString(); - if ((startPos.Char<=s.length() || startPos.LinenewS.length() ) { + if ((startPos.ch<=s.length() || startPos.linenewS.length() ) { //selection has whole block - endPos.Line = foldRange->toLine; - endPos.Char = mDocument->getString(endPos.Line-1).length()+1; + endPos.line = foldRange->toLine; + endPos.ch = mDocument->getString(endPos.line-1).length()+1; } else { return; } @@ -5411,17 +5383,17 @@ void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SynSelectio } QStringList deleted=getContent(startPos,endPos,mode); switch(mode) { - case SynSelectionMode::smNormal: + case SynSelectionMode::Normal: if (mDocument->count() > 0) { // Create a string that contains everything on the first line up // to the selection mark, and everything on the last line after // the selection mark. - QString TempString = mDocument->getString(startPos.Line - 1).mid(0, startPos.Char - 1) - + mDocument->getString(endPos.Line - 1).mid(endPos.Char-1); + QString TempString = mDocument->getString(startPos.line - 1).mid(0, startPos.ch - 1) + + mDocument->getString(endPos.line - 1).mid(endPos.ch-1); // bool collapsed=foldCollapsedBetween(BB.Line,BE.Line); // Delete all lines in the selection range. - mDocument->deleteLines(startPos.Line, endPos.Line - startPos.Line); - properSetLine(startPos.Line-1,TempString); + mDocument->deleteLines(startPos.line, endPos.line - startPos.line); + properSetLine(startPos.line-1,TempString); UpdateMarks = true; internalSetCaretXY(startPos); // if (collapsed) { @@ -5432,12 +5404,12 @@ void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SynSelectio // } } break; - case SynSelectionMode::smColumn: + case SynSelectionMode::Column: { - int First = startPos.Line - 1; - int ColFrom = charToColumn(startPos.Line, startPos.Char); - int Last = endPos.Line - 1; - int ColTo = charToColumn(endPos.Line, endPos.Char); + int First = startPos.line - 1; + int ColFrom = charToColumn(startPos.line, startPos.ch); + int Last = endPos.line - 1; + int ColTo = charToColumn(endPos.line, endPos.ch); if (ColFrom > ColTo) std::swap(ColFrom, ColTo); if (First > Last) @@ -5456,24 +5428,24 @@ void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SynSelectio // updating is needed here. break; } - case SynSelectionMode::smLine: - if (endPos.Line == mDocument->count()) { - mDocument->putString(endPos.Line - 1,""); - mDocument->deleteLines(startPos.Line-1,endPos.Line-startPos.Line); + case SynSelectionMode::Line: + if (endPos.line == mDocument->count()) { + mDocument->putString(endPos.line - 1,""); + mDocument->deleteLines(startPos.line-1,endPos.line-startPos.line); } else { - mDocument->deleteLines(startPos.Line-1,endPos.Line-startPos.Line+1); + mDocument->deleteLines(startPos.line-1,endPos.line-startPos.line+1); } // smLine deletion always resets to first column. - internalSetCaretXY(BufferCoord{1, startPos.Line}); + internalSetCaretXY(BufferCoord{1, startPos.line}); UpdateMarks = true; MarkOffset = 1; break; } // Update marks if (UpdateMarks) - doLinesDeleted(startPos.Line, endPos.Line - startPos.Line + MarkOffset); + doLinesDeleted(startPos.line, endPos.line - startPos.line + MarkOffset); if (!mUndoing) { - mUndoList->AddChange(SynChangeReason::crDelete, + mUndoList->addChange(SynChangeReason::Delete, startPos, endPos, deleted, @@ -5489,26 +5461,26 @@ void SynEdit::doInsertText(const BufferCoord& pos, if (startLine>endLine) std::swap(startLine,endLine); - if (mode == SynSelectionMode::smNormal) { - PSynEditFoldRange foldRange = foldStartAtLine(pos.Line); - QString s = mDocument->getString(pos.Line-1); - if ((foldRange) && foldRange->collapsed && pos.Char>s.length()+1) + if (mode == SynSelectionMode::Normal) { + PSynEditFoldRange foldRange = foldStartAtLine(pos.line); + QString s = mDocument->getString(pos.line-1); + if ((foldRange) && foldRange->collapsed && pos.ch>s.length()+1) return; } int insertedLines = 0; BufferCoord newPos; switch(mode){ - case SynSelectionMode::smNormal: + case SynSelectionMode::Normal: insertedLines = doInsertTextByNormalMode(pos,text, newPos); - doLinesInserted(pos.Line+1, insertedLines); + doLinesInserted(pos.line+1, insertedLines); break; - case SynSelectionMode::smColumn: + case SynSelectionMode::Column: insertedLines = doInsertTextByColumnMode(pos,text, newPos, startLine,endLine); doLinesInserted(endLine-insertedLines+1,insertedLines); break; - case SynSelectionMode::smLine: + case SynSelectionMode::Line: insertedLines = doInsertTextByLineMode(pos,text, newPos); - doLinesInserted(pos.Line, insertedLines); + doLinesInserted(pos.line, insertedLines); break; } internalSetCaretXY(newPos); @@ -5523,22 +5495,22 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& bool bChangeScroll; // int SpaceCount; int result = 0; - int startLine = pos.Line; - QString line=mDocument->getString(pos.Line-1); - sLeftSide = line.mid(0, pos.Char - 1); - if (pos.Char - 1 > sLeftSide.length()) { + int startLine = pos.line; + QString line=mDocument->getString(pos.line-1); + sLeftSide = line.mid(0, pos.ch - 1); + if (pos.ch - 1 > sLeftSide.length()) { if (stringIsBlank(sLeftSide)) sLeftSide = GetLeftSpacing(displayX() - 1, true); else - sLeftSide += QString(pos.Char - 1 - sLeftSide.length(),' '); + sLeftSide += QString(pos.ch - 1 - sLeftSide.length(),' '); } - sRightSide = line.mid(pos.Char - 1); + sRightSide = line.mid(pos.ch - 1); // if (mUndoing) { // SpaceCount = 0; // } else { // SpaceCount = leftSpaces(sLeftSide); // } - int caretY=pos.Line; + int caretY=pos.line; // step1: insert the first line of Value into current line if (text.length()>1) { if (!mUndoing && mHighlighter && mOptions.testFlag(eoAutoIndent)) { @@ -5565,7 +5537,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& // && !mHighlighter->isLastLineStringNotFinished( // mHighlighter->getRangeState().state); // } - caretY=pos.Line+i; + caretY=pos.line+i; // mStatusChanges.setFlag(SynStatusChange::scCaretY); if (text[i].isEmpty()) { if (i==text.length()-1) { @@ -5602,10 +5574,10 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList& newPos=BufferCoord{str.length() - sRightSide.length()+1,caretY}; onLinesPutted(startLine-1,result+1); if (!mUndoing) { - mUndoList->AddChange( - SynChangeReason::crInsert, + mUndoList->addChange( + SynChangeReason::Insert, pos,newPos, - QStringList(),SynSelectionMode::smNormal); + QStringList(),SynSelectionMode::Normal); } return result; } @@ -5622,7 +5594,7 @@ int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& int insertCol = insertCoord.Column; line = startLine; if (!mUndoing) { - mUndoList->BeginBlock(); + mUndoList->beginBlock(); } int i=0; while(line<=endLine) { @@ -5634,12 +5606,12 @@ int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& mDocument->add(""); if (!mUndoing) { result++; - lineBreakPos.Line = line - 1; - lineBreakPos.Char = mDocument->getString(line - 2).length() + 1; - mUndoList->AddChange(SynChangeReason::crLineBreak, + lineBreakPos.line = line - 1; + lineBreakPos.ch = mDocument->getString(line - 2).length() + 1; + mUndoList->addChange(SynChangeReason::LineBreak, lineBreakPos, lineBreakPos, - QStringList(), SynSelectionMode::smNormal); + QStringList(), SynSelectionMode::Normal); } } else { tempString = mDocument->getString(line - 1); @@ -5655,12 +5627,12 @@ int SynEdit::doInsertTextByColumnMode(const BufferCoord& pos, const QStringList& properSetLine(line - 1, tempString); // Add undo change here from PasteFromClipboard if (!mUndoing) { - mUndoList->AddChange( - SynChangeReason::crInsert, + mUndoList->addChange( + SynChangeReason::Insert, BufferCoord{insertPos, line}, BufferCoord{insertPos+str.length(), line}, QStringList(), - SynSelectionMode::smNormal); + SynSelectionMode::Normal); } if (iEndBlock(); + mUndoList->endBlock(); } return result; } @@ -5684,7 +5656,7 @@ int SynEdit::doInsertTextByLineMode(const BufferCoord& pos, const QStringList& t QString Str; int Result = 0; newPos=pos; - newPos.Char=1; + newPos.ch=1; // mCaretX = 1; // emit statusChanged(SynStatusChange::scCaretX); // Insert string before current line @@ -5694,15 +5666,15 @@ int SynEdit::doInsertTextByLineMode(const BufferCoord& pos, const QStringList& t Result++; } properSetLine(mCaretY - 1, Str); - newPos.Line++; + newPos.line++; // mCaretY++; // mStatusChanges.setFlag(SynStatusChange::scCaretY); } if (!mUndoing) { - mUndoList->AddChange( - SynChangeReason::crInsert, - BufferCoord{1,pos.Line},newPos, - QStringList(),SynSelectionMode::smLine); + mUndoList->addChange( + SynChangeReason::Insert, + BufferCoord{1,pos.line},newPos, + QStringList(),SynSelectionMode::Line); } return Result; } @@ -5712,19 +5684,14 @@ void SynEdit::deleteFromTo(const BufferCoord &start, const BufferCoord &end) if (mReadOnly) return; doOnPaintTransient(SynTransientType::ttBefore); - if ((start.Char != end.Char) || (start.Line != end.Line)) { - BufferCoord oldCaret = caretXY(); - mUndoList->BeginBlock(); - mUndoList->AddChange(SynChangeReason::crCaret, oldCaret, start, - QStringList(), activeSelectionMode()); - mUndoList->AddChange(SynChangeReason::crSelection, - mBlockBegin, - mBlockEnd, - QStringList(),activeSelectionMode()); + if ((start.ch != end.ch) || (start.line != end.line)) { + mUndoList->beginBlock(); + addCaretToUndo(); + addSelectionToUndo(); setBlockBegin(start); setBlockEnd(end); - doDeleteText(start,end,SynSelectionMode::smNormal); - mUndoList->EndBlock(); + doDeleteText(start,end,SynSelectionMode::Normal); + mUndoList->endBlock(); internalSetCaretXY(start); } doOnPaintTransient(SynTransientType::ttAfter); @@ -5924,16 +5891,12 @@ void SynEdit::ExecuteCommand(SynEditorCommand Command, QChar AChar, void *pData) insertLine(true); break; case SynEditorCommand::ecLineBreakAtEnd: - mUndoList->BeginBlock(); - mUndoList->AddChange( - SynChangeReason::crCaret, - caretXY(), - caretXY(), - QStringList(), - activeSelectionMode()); + mUndoList->beginBlock(); + addCaretToUndo(); + addSelectionToUndo(); moveCaretToLineEnd(false); insertLine(true); - mUndoList->EndBlock(); + mUndoList->endBlock(); break; case SynEditorCommand::ecTab: doTabKey(); @@ -6000,13 +5963,13 @@ void SynEdit::ExecuteCommand(SynEditorCommand Command, QChar AChar, void *pData) doToggleBlockComment(); break; case SynEditorCommand::ecNormalSelect: - setSelectionMode(SynSelectionMode::smNormal); + setSelectionMode(SynSelectionMode::Normal); break; case SynEditorCommand::ecLineSelect: - setSelectionMode(SynSelectionMode::smLine); + setSelectionMode(SynSelectionMode::Line); break; case SynEditorCommand::ecColumnSelect: - setSelectionMode(SynSelectionMode::smColumn); + setSelectionMode(SynSelectionMode::Column); break; case SynEditorCommand::ecScrollLeft: horizontalScrollBar()->setValue(horizontalScrollBar()->value()-mMouseWheelScrollSpeed); @@ -6023,7 +5986,7 @@ void SynEdit::ExecuteCommand(SynEditorCommand Command, QChar AChar, void *pData) case SynEditorCommand::ecMatchBracket: { BufferCoord coord = getMatchingBracket(); - if (coord.Char!=0 && coord.Line!=0) + if (coord.ch!=0 && coord.line!=0) internalSetCaretXY(coord); } break; @@ -6275,12 +6238,13 @@ void SynEdit::mousePressEvent(QMouseEvent *event) QAbstractScrollArea::mousePressEvent(event); + BufferCoord oldCaret=caretXY(); if (button == Qt::RightButton) { if (mOptions.testFlag(eoRightMouseMovesCursor) && ( (selAvail() && ! isPointInSelection(displayToBufferPos(pixelsToRowColumn(X, Y)))) || ! selAvail())) { invalidateSelection(); - mBlockEnd=mBlockBegin; + //mBlockEnd=mBlockBegin; computeCaret(); }else { return; @@ -6294,7 +6258,7 @@ void SynEdit::mousePressEvent(QMouseEvent *event) computeCaret(); mStateFlags.setFlag(SynStateFlag::sfWaitForDragging,false); if (bWasSel && mOptions.testFlag(eoDragDropEditing) && (X >= mGutterWidth + 2) - && (mSelectionMode == SynSelectionMode::smNormal) && isPointInSelection(displayToBufferPos(pixelsToRowColumn(X, Y))) ) { + && (mSelectionMode == SynSelectionMode::Normal) && isPointInSelection(displayToBufferPos(pixelsToRowColumn(X, Y))) ) { bStartDrag = true; } if (bStartDrag) { @@ -6305,9 +6269,9 @@ void SynEdit::mousePressEvent(QMouseEvent *event) //code from above and SetBlockEnd will take care of proper invalidation setBlockEnd(caretXY()); } else if (mOptions.testFlag(eoAltSetsColumnMode) && - (mActiveSelectionMode != SynSelectionMode::smLine)) { + (mActiveSelectionMode != SynSelectionMode::Line)) { if (event->modifiers() == Qt::AltModifier) - setActiveSelectionMode(SynSelectionMode::smColumn); + setActiveSelectionMode(SynSelectionMode::Column); else setActiveSelectionMode(selectionMode()); //Selection mode must be set before calling SetBlockBegin @@ -6316,6 +6280,10 @@ void SynEdit::mousePressEvent(QMouseEvent *event) computeScroll(false); } } + if (oldCaret!=caretXY()) { + if (mOptions.testFlag(SynEditorOption::eoGroupUndo)) + mUndoList->addGroupBreak(); + } } void SynEdit::mouseReleaseEvent(QMouseEvent *event) @@ -6328,7 +6296,7 @@ void SynEdit::mouseReleaseEvent(QMouseEvent *event) processGutterClick(event); } - + BufferCoord oldCaret=caretXY(); if (mStateFlags.testFlag(SynStateFlag::sfWaitForDragging) && !mStateFlags.testFlag(SynStateFlag::sfDblClicked)) { computeCaret(); @@ -6338,6 +6306,10 @@ void SynEdit::mouseReleaseEvent(QMouseEvent *event) mStateFlags.setFlag(SynStateFlag::sfWaitForDragging, false); } mStateFlags.setFlag(SynStateFlag::sfDblClicked,false); + if (oldCaret!=caretXY()) { + if (mOptions.testFlag(SynEditorOption::eoGroupUndo)) + mUndoList->addGroupBreak(); + } } void SynEdit::mouseMoveEvent(QMouseEvent *event) @@ -6358,9 +6330,9 @@ void SynEdit::mouseMoveEvent(QMouseEvent *event) } } else if ((buttons == Qt::LeftButton)) { if (mOptions.testFlag(eoAltSetsColumnMode) && - (mActiveSelectionMode != SynSelectionMode::smLine)) { + (mActiveSelectionMode != SynSelectionMode::Line)) { if (event->modifiers() == Qt::AltModifier) - setActiveSelectionMode(SynSelectionMode::smColumn); + setActiveSelectionMode(SynSelectionMode::Column); else setActiveSelectionMode(selectionMode()); } @@ -6387,10 +6359,10 @@ void SynEdit::inputMethodEvent(QInputMethodEvent *event) QString oldString = mInputPreeditString; mInputPreeditString = event->preeditString(); if (oldString!=mInputPreeditString) { - if (mActiveSelectionMode==SynSelectionMode::smColumn) { + if (mActiveSelectionMode==SynSelectionMode::Column) { BufferCoord selBegin = blockBegin(); BufferCoord selEnd = blockEnd(); - invalidateLines(selBegin.Line,selEnd.Line); + invalidateLines(selBegin.line,selEnd.line); } else invalidateLine(mCaretY); } @@ -6489,40 +6461,40 @@ void SynEdit::dropEvent(QDropEvent *event) int topLine = mTopLine; int leftChar = mLeftChar; QStringList text=splitStrings(event->mimeData()->text()); - mUndoList->BeginBlock(); + mUndoList->beginBlock(); addLeftTopToUndo(); addCaretToUndo(); addSelectionToUndo(); internalSetCaretXY(coord); if (event->proposedAction() == Qt::DropAction::CopyAction) { //just copy it - doInsertText(coord,text,mActiveSelectionMode,coord.Line,coord.Line+text.length()-1); + doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); } else if (event->proposedAction() == Qt::DropAction::MoveAction) { if (coord < mDragSelBeginSave ) { //delete old doDeleteText(mDragSelBeginSave,mDragSelEndSave,mActiveSelectionMode); //paste to new position - doInsertText(coord,text,mActiveSelectionMode,coord.Line,coord.Line+text.length()-1); + doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); } else { //paste to new position - doInsertText(coord,text,mActiveSelectionMode,coord.Line,coord.Line+text.length()-1); + doInsertText(coord,text,mActiveSelectionMode,coord.line,coord.line+text.length()-1); //delete old doDeleteText(mDragSelBeginSave,mDragSelEndSave,mActiveSelectionMode); //set caret to right pos - if (mDragSelBeginSave.Line == mDragSelEndSave.Line) { - if (coord.Line == mDragSelEndSave.Line) { - coord.Char -= mDragSelEndSave.Char-mDragSelBeginSave.Char; + if (mDragSelBeginSave.line == mDragSelEndSave.line) { + if (coord.line == mDragSelEndSave.line) { + coord.ch -= mDragSelEndSave.ch-mDragSelBeginSave.ch; } } else { - if (coord.Line == mDragSelEndSave.Line) { - coord.Char -= mDragSelEndSave.Char-1; + if (coord.line == mDragSelEndSave.line) { + coord.ch -= mDragSelEndSave.ch-1; } else { - coord.Line -= mDragSelEndSave.Line-mDragSelBeginSave.Line; - topLine -= mDragSelEndSave.Line-mDragSelBeginSave.Line; + coord.line -= mDragSelEndSave.line-mDragSelBeginSave.line; + topLine -= mDragSelEndSave.line-mDragSelBeginSave.line; } } } - mUndoList->EndBlock(); + mUndoList->endBlock(); } event->acceptProposedAction(); @@ -6583,8 +6555,9 @@ void SynEdit::setModified(bool Value) } if (Value != mModified) { mModified = Value; - if (mOptions.testFlag(SynEditorOption::eoGroupUndo) && (!Value) && mUndoList->CanUndo()) - mUndoList->AddGroupBreak(); + if (mOptions.testFlag(SynEditorOption::eoGroupUndo) && (!Value) ) { + mUndoList->addGroupBreak(); + } mUndoList->setInitialState(!Value); emit statusChanged(SynStatusChange::scModifyChanged); } @@ -6633,13 +6606,13 @@ void SynEdit::onLinesChanged() mStateFlags.setFlag(SynStateFlag::sfLinesChanging, false); updateScrollbars(); - if (mActiveSelectionMode == SynSelectionMode::smColumn) { + if (mActiveSelectionMode == SynSelectionMode::Column) { BufferCoord oldBlockStart = blockBegin(); BufferCoord oldBlockEnd = blockEnd(); - oldBlockStart.Char = mCaretX; - int colEnd = charToColumn(oldBlockStart.Line,oldBlockStart.Char); - int charEnd = columnToChar(oldBlockEnd.Line,colEnd); - oldBlockEnd.Char = charEnd; + oldBlockStart.ch = mCaretX; + int colEnd = charToColumn(oldBlockStart.line,oldBlockStart.ch); + int charEnd = columnToChar(oldBlockEnd.line,colEnd); + oldBlockEnd.ch = charEnd; setBlockBegin(oldBlockStart); setBlockEnd(oldBlockEnd); } else { @@ -6720,8 +6693,8 @@ void SynEdit::onUndoAdded() // we have to clear the redo information, since adding undo info removes // the necessary context to undo earlier edit actions if (! mUndoList->insideRedo() && - mUndoList->PeekItem() && (mUndoList->PeekItem()->changeReason()!=SynChangeReason::crGroupBreak)) - mRedoList->Clear(); + mUndoList->peekItem() && (mUndoList->peekItem()->changeReason()!=SynChangeReason::GroupBreak)) + mRedoList->clear(); if (mUndoList->blockCount() == 0 ) onChanged(); } @@ -6745,10 +6718,10 @@ void SynEdit::setActiveSelectionMode(const SynSelectionMode &Value) BufferCoord SynEdit::blockEnd() const { - if (mActiveSelectionMode==SynSelectionMode::smColumn) + if (mActiveSelectionMode==SynSelectionMode::Column) return mBlockEnd; - if ((mBlockEnd.Line < mBlockBegin.Line) - || ((mBlockEnd.Line == mBlockBegin.Line) && (mBlockEnd.Char < mBlockBegin.Char))) + if ((mBlockEnd.line < mBlockBegin.line) + || ((mBlockEnd.line == mBlockBegin.line) && (mBlockEnd.ch < mBlockBegin.ch))) return mBlockBegin; else return mBlockEnd; @@ -6757,29 +6730,29 @@ BufferCoord SynEdit::blockEnd() const void SynEdit::setBlockEnd(BufferCoord Value) { //setActiveSelectionMode(mSelectionMode); - Value.Line = minMax(Value.Line, 1, mDocument->count()); - if (mActiveSelectionMode == SynSelectionMode::smNormal) { - if (Value.Line >= 1 && Value.Line <= mDocument->count()) - Value.Char = std::min(Value.Char, getDisplayStringAtLine(Value.Line).length() + 1); + Value.line = minMax(Value.line, 1, mDocument->count()); + if (mActiveSelectionMode == SynSelectionMode::Normal) { + if (Value.line >= 1 && Value.line <= mDocument->count()) + Value.ch = std::min(Value.ch, getDisplayStringAtLine(Value.line).length() + 1); else - Value.Char = 1; + Value.ch = 1; } else { int maxLen = mDocument->lengthOfLongestLine(); if (highlighter()) maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen); - Value.Char = minMax(Value.Char, 1, maxLen+1); + Value.ch = minMax(Value.ch, 1, maxLen+1); } - if (Value.Char != mBlockEnd.Char || Value.Line != mBlockEnd.Line) { - if (mActiveSelectionMode == SynSelectionMode::smColumn && Value.Char != mBlockEnd.Char) { + if (Value.ch != mBlockEnd.ch || Value.line != mBlockEnd.line) { + if (mActiveSelectionMode == SynSelectionMode::Column && Value.ch != mBlockEnd.ch) { invalidateLines( - std::min(mBlockBegin.Line, std::min(mBlockEnd.Line, Value.Line)), - std::max(mBlockBegin.Line, std::max(mBlockEnd.Line, Value.Line))); + std::min(mBlockBegin.line, std::min(mBlockEnd.line, Value.line)), + std::max(mBlockBegin.line, std::max(mBlockEnd.line, Value.line))); mBlockEnd = Value; } else { - int nLine = mBlockEnd.Line; + int nLine = mBlockEnd.line; mBlockEnd = Value; - if (mActiveSelectionMode != SynSelectionMode::smColumn || mBlockBegin.Char != mBlockEnd.Char) - invalidateLines(nLine, mBlockEnd.Line); + if (mActiveSelectionMode != SynSelectionMode::Column || mBlockBegin.ch != mBlockEnd.ch) + invalidateLines(nLine, mBlockEnd.line); } setStatusChanged(SynStatusChange::scSelection); } @@ -6787,12 +6760,12 @@ void SynEdit::setBlockEnd(BufferCoord Value) void SynEdit::setSelLength(int Value) { - if (mBlockBegin.Line>mDocument->count() || mBlockBegin.Line<=0) + if (mBlockBegin.line>mDocument->count() || mBlockBegin.line<=0) return; if (Value >= 0) { - int y = mBlockBegin.Line; - int ch = mBlockBegin.Char; + int y = mBlockBegin.line; + int ch = mBlockBegin.ch; int x = ch + Value; QString line; while (y<=mDocument->count()) { @@ -6812,8 +6785,8 @@ void SynEdit::setSelLength(int Value) BufferCoord iNewEnd{x,y}; setCaretAndSelection(iNewEnd, mBlockBegin, iNewEnd); } else { - int y = mBlockBegin.Line; - int ch = mBlockBegin.Char; + int y = mBlockBegin.line; + int ch = mBlockBegin.ch; int x = ch + Value; QString line; while (y>=1) { @@ -6842,10 +6815,10 @@ void SynEdit::setSelText(const QString &text) BufferCoord SynEdit::blockBegin() const { - if (mActiveSelectionMode==SynSelectionMode::smColumn) + if (mActiveSelectionMode==SynSelectionMode::Column) return mBlockBegin; - if ((mBlockEnd.Line < mBlockBegin.Line) - || ((mBlockEnd.Line == mBlockBegin.Line) && (mBlockEnd.Char < mBlockBegin.Char))) + if ((mBlockEnd.line < mBlockBegin.line) + || ((mBlockEnd.line == mBlockBegin.line) && (mBlockEnd.ch < mBlockBegin.ch))) return mBlockEnd; else return mBlockBegin; @@ -6856,25 +6829,25 @@ void SynEdit::setBlockBegin(BufferCoord value) int nInval1, nInval2; bool SelChanged; //setActiveSelectionMode(mSelectionMode); - value.Line = minMax(value.Line, 1, mDocument->count()); - if (mActiveSelectionMode == SynSelectionMode::smNormal) { - if (value.Line >= 1 && value.Line <= mDocument->count()) - value.Char = std::min(value.Char, getDisplayStringAtLine(value.Line).length() + 1); + value.line = minMax(value.line, 1, mDocument->count()); + if (mActiveSelectionMode == SynSelectionMode::Normal) { + if (value.line >= 1 && value.line <= mDocument->count()) + value.ch = std::min(value.ch, getDisplayStringAtLine(value.line).length() + 1); else - value.Char = 1; + value.ch = 1; } else { int maxLen = mDocument->lengthOfLongestLine(); if (highlighter()) maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen); - value.Char = minMax(value.Char, 1, maxLen+1); + value.ch = minMax(value.ch, 1, maxLen+1); } if (selAvail()) { - if (mBlockBegin.Line < mBlockEnd.Line) { - nInval1 = std::min(value.Line, mBlockBegin.Line); - nInval2 = std::max(value.Line, mBlockEnd.Line); + if (mBlockBegin.line < mBlockEnd.line) { + nInval1 = std::min(value.line, mBlockBegin.line); + nInval2 = std::max(value.line, mBlockEnd.line); } else { - nInval1 = std::min(value.Line, mBlockEnd.Line); - nInval2 = std::max(value.Line, mBlockBegin.Line); + nInval1 = std::min(value.line, mBlockEnd.line); + nInval2 = std::max(value.line, mBlockBegin.line); }; mBlockBegin = value; mBlockEnd = value; @@ -6882,8 +6855,8 @@ void SynEdit::setBlockBegin(BufferCoord value) SelChanged = true; } else { SelChanged = - (mBlockBegin.Char != value.Char) || (mBlockBegin.Line != value.Line) || - (mBlockEnd.Char != value.Char) || (mBlockEnd.Line != value.Line); + (mBlockBegin.ch != value.ch) || (mBlockBegin.line != value.line) || + (mBlockEnd.ch != value.ch) || (mBlockEnd.line != value.line); mBlockBegin = value; mBlockEnd = value; } diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 57968258..209daab4 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -184,8 +184,8 @@ public: BufferCoord displayToBufferPos(const DisplayCoord& p) const; //normalized buffer coord operations - ContentsCoord fromBufferCoord(const BufferCoord& p) const; - ContentsCoord createNormalizedBufferCoord(int aChar,int aLine) const; +// ContentsCoord fromBufferCoord(const BufferCoord& p) const; +// ContentsCoord createNormalizedBufferCoord(int aChar,int aLine) const; // QStringList getContents(const ContentsCoord& pStart,const ContentsCoord& pEnd); // QString getJoinedContents(const ContentsCoord& pStart,const ContentsCoord& pEnd, const QString& joinStr); @@ -272,7 +272,7 @@ public: void addLeftTopToUndo(); void addSelectionToUndo(); void replaceAll(const QString& text) { - mUndoList->AddChange(SynChangeReason::crSelection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode()); + mUndoList->addChange(SynChangeReason::Selection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode()); selectAll(); setSelText(text); } diff --git a/RedPandaIDE/qsynedit/TextBuffer.cpp b/RedPandaIDE/qsynedit/TextBuffer.cpp index 2e8096eb..9e3c1ad3 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.cpp +++ b/RedPandaIDE/qsynedit/TextBuffer.cpp @@ -846,7 +846,7 @@ SynEditUndoList::SynEditUndoList():QObject() mInitialChangeNumber = 0; } -void SynEditUndoList::AddChange(SynChangeReason AReason, const BufferCoord &AStart, +void SynEditUndoList::addChange(SynChangeReason AReason, const BufferCoord &AStart, const BufferCoord &AEnd, const QStringList& ChangeText, SynSelectionMode SelMode) { @@ -867,31 +867,32 @@ void SynEditUndoList::AddChange(SynChangeReason AReason, const BufferCoord &ASta PSynEditUndoItem NewItem = std::make_shared(AReason, SelMode,AStart,AEnd,ChangeText, changeNumber); - PushItem(NewItem); + pushItem(NewItem); } -void SynEditUndoList::AddGroupBreak() +void SynEditUndoList::addGroupBreak() { - //Add the GroupBreak even if ItemCount = 0. Since items are stored in - //reverse order in TCustomSynEdit.fRedoList, a GroupBreak could be lost. - if (LastChangeReason() != SynChangeReason::crGroupBreak) { - AddChange(SynChangeReason::crGroupBreak, {0,0}, {0,0}, QStringList(), SynSelectionMode::smNormal); + if (!canUndo()) + return; + + if (lastChangeReason() != SynChangeReason::GroupBreak) { + addChange(SynChangeReason::GroupBreak, {0,0}, {0,0}, QStringList(), SynSelectionMode::Normal); } } -void SynEditUndoList::BeginBlock() +void SynEditUndoList::beginBlock() { mBlockCount++; mBlockChangeNumber = mNextChangeNumber; } -void SynEditUndoList::Clear() +void SynEditUndoList::clear() { mItems.clear(); mFullUndoImposible = false; } -void SynEditUndoList::DeleteItem(int index) +void SynEditUndoList::deleteItem(int index) { if (index <0 || index>=mItems.count()) { ListIndexOutOfBounds(index); @@ -899,7 +900,7 @@ void SynEditUndoList::DeleteItem(int index) mItems.removeAt(index); } -void SynEditUndoList::EndBlock() +void SynEditUndoList::endBlock() { if (mBlockCount > 0) { mBlockCount--; @@ -909,16 +910,16 @@ void SynEditUndoList::EndBlock() mNextChangeNumber++; if (mNextChangeNumber == 0) mNextChangeNumber++; - if (mItems.count() > 0 && PeekItem()->changeNumber() == iBlockID) + if (mItems.count() > 0 && peekItem()->changeNumber() == iBlockID) emit addedUndo(); } } } -SynChangeReason SynEditUndoList::LastChangeReason() +SynChangeReason SynEditUndoList::lastChangeReason() { if (mItems.count() == 0) - return SynChangeReason::crNothing; + return SynChangeReason::Nothing; else return mItems.last()->changeReason(); } @@ -928,12 +929,12 @@ bool SynEditUndoList::isEmpty() return mItems.count()==0; } -void SynEditUndoList::Lock() +void SynEditUndoList::lock() { mLockCount++; } -PSynEditUndoItem SynEditUndoList::PeekItem() +PSynEditUndoItem SynEditUndoList::peekItem() { if (mItems.count() == 0) return PSynEditUndoItem(); @@ -941,7 +942,7 @@ PSynEditUndoItem SynEditUndoList::PeekItem() return mItems.last(); } -PSynEditUndoItem SynEditUndoList::PopItem() +PSynEditUndoItem SynEditUndoList::popItem() { if (mItems.count() == 0) return PSynEditUndoItem(); @@ -952,28 +953,28 @@ PSynEditUndoItem SynEditUndoList::PopItem() } } -void SynEditUndoList::PushItem(PSynEditUndoItem Item) +void SynEditUndoList::pushItem(PSynEditUndoItem Item) { if (!Item) return; mItems.append(Item); ensureMaxEntries(); - if (Item->changeReason()!= SynChangeReason::crGroupBreak) + if (Item->changeReason()!= SynChangeReason::GroupBreak) emit addedUndo(); } -void SynEditUndoList::Unlock() +void SynEditUndoList::unlock() { if (mLockCount > 0) mLockCount--; } -bool SynEditUndoList::CanUndo() +bool SynEditUndoList::canUndo() { return mItems.count()>0; } -int SynEditUndoList::ItemCount() +int SynEditUndoList::itemCount() { return mItems.count(); } @@ -993,10 +994,10 @@ void SynEditUndoList::setMaxUndoActions(int maxUndoActions) bool SynEditUndoList::initialState() { - if (ItemCount() == 0) { + if (itemCount() == 0) { return mInitialChangeNumber == 0; } else { - return PeekItem()->changeNumber() == mInitialChangeNumber; + return peekItem()->changeNumber() == mInitialChangeNumber; } } @@ -1011,15 +1012,15 @@ PSynEditUndoItem SynEditUndoList::item(int index) void SynEditUndoList::setInitialState(const bool Value) { if (Value) { - if (ItemCount() == 0) + if (itemCount() == 0) mInitialChangeNumber = 0; else - mInitialChangeNumber = PeekItem()->changeNumber(); - } else if (ItemCount() == 0) { + mInitialChangeNumber = peekItem()->changeNumber(); + } else if (itemCount() == 0) { if (mInitialChangeNumber == 0) { mInitialChangeNumber = -1; } - } else if (PeekItem()->changeNumber() == mInitialChangeNumber) { + } else if (peekItem()->changeNumber() == mInitialChangeNumber) { mInitialChangeNumber = -1; } } diff --git a/RedPandaIDE/qsynedit/TextBuffer.h b/RedPandaIDE/qsynedit/TextBuffer.h index 5d41b180..79bf9144 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.h +++ b/RedPandaIDE/qsynedit/TextBuffer.h @@ -161,16 +161,16 @@ private: }; enum class SynChangeReason { - crInsert, - crDelete, - crCaret, //just restore the Caret, allowing better Undo behavior - crSelection, //restore Selection - crGroupBreak, - crLeftTop, - crLineBreak, - crMoveSelectionUp, - crMoveSelectionDown, - crNothing + Insert, + Delete, + Caret, //just restore the Caret, allowing better Undo behavior + Selection, //restore Selection + GroupBreak, + LeftTop, + LineBreak, + MoveSelectionUp, + MoveSelectionDown, + Nothing // undo list empty }; class SynEditUndoItem { private: @@ -202,24 +202,24 @@ class SynEditUndoList : public QObject { public: explicit SynEditUndoList(); - void AddChange(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd, + void addChange(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd, const QStringList& ChangeText, SynSelectionMode SelMode); - void AddGroupBreak(); - void BeginBlock(); - void Clear(); - void DeleteItem(int index); - void EndBlock(); - SynChangeReason LastChangeReason(); + void addGroupBreak(); + void beginBlock(); + void clear(); + void deleteItem(int index); + void endBlock(); + SynChangeReason lastChangeReason(); bool isEmpty(); - void Lock(); - PSynEditUndoItem PeekItem(); - PSynEditUndoItem PopItem(); - void PushItem(PSynEditUndoItem Item); - void Unlock(); + void lock(); + PSynEditUndoItem peekItem(); + PSynEditUndoItem popItem(); + void pushItem(PSynEditUndoItem Item); + void unlock(); - bool CanUndo(); - int ItemCount(); + bool canUndo(); + int itemCount(); int maxUndoActions() const; void setMaxUndoActions(int maxUndoActions); diff --git a/RedPandaIDE/qsynedit/TextPainter.cpp b/RedPandaIDE/qsynedit/TextPainter.cpp index 4edb3a81..85acee48 100644 --- a/RedPandaIDE/qsynedit/TextPainter.cpp +++ b/RedPandaIDE/qsynedit/TextPainter.cpp @@ -133,7 +133,7 @@ void SynEditTextPainter::paintGutter(const QRect& clip) if (edit->mGutter.activeLineTextColor().isValid()) { if ( (edit->mCaretY==vLine) || - (edit->mActiveSelectionMode == SynSelectionMode::smColumn && vLine >= selectionStart.Line && vLine <= selectionEnd.Line) + (edit->mActiveSelectionMode == SynSelectionMode::Column && vLine >= selectionStart.line && vLine <= selectionEnd.line) ) painter->setPen(edit->mGutter.activeLineTextColor()); else @@ -253,59 +253,59 @@ void SynEditTextPainter::ComputeSelectionInfo() if (!edit->mHideSelection || edit->hasFocus()) { bAnySelection = true; // Get the *real* start of the selected area. - if (edit->mBlockBegin.Line < edit->mBlockEnd.Line) { + if (edit->mBlockBegin.line < edit->mBlockEnd.line) { vStart = edit->mBlockBegin; vEnd = edit->mBlockEnd; - } else if (edit->mBlockBegin.Line > edit->mBlockEnd.Line) { + } else if (edit->mBlockBegin.line > edit->mBlockEnd.line) { vEnd = edit->mBlockBegin; vStart = edit->mBlockEnd; - } else if (edit->mBlockBegin.Char != edit->mBlockEnd.Char) { + } else if (edit->mBlockBegin.ch != edit->mBlockEnd.ch) { // it is only on this line. - vStart.Line = edit->mBlockBegin.Line; - vEnd.Line = vStart.Line; - if (edit->mBlockBegin.Char < edit->mBlockEnd.Char) { - vStart.Char = edit->mBlockBegin.Char; - vEnd.Char = edit->mBlockEnd.Char; + vStart.line = edit->mBlockBegin.line; + vEnd.line = vStart.line; + if (edit->mBlockBegin.ch < edit->mBlockEnd.ch) { + vStart.ch = edit->mBlockBegin.ch; + vEnd.ch = edit->mBlockEnd.ch; } else { - vStart.Char = edit->mBlockEnd.Char; - vEnd.Char = edit->mBlockBegin.Char; + vStart.ch = edit->mBlockEnd.ch; + vEnd.ch = edit->mBlockBegin.ch; } } else bAnySelection = false; if (edit->mInputPreeditString.length()>0) { - if (vStart.Line == edit->mCaretY && vStart.Char >=edit->mCaretX) { - vStart.Char+=edit->mInputPreeditString.length(); + if (vStart.line == edit->mCaretY && vStart.ch >=edit->mCaretX) { + vStart.ch+=edit->mInputPreeditString.length(); } - if (vEnd.Line == edit->mCaretY && vEnd.Char >edit->mCaretX) { - vEnd.Char+=edit->mInputPreeditString.length(); + if (vEnd.line == edit->mCaretY && vEnd.ch >edit->mCaretX) { + vEnd.ch+=edit->mInputPreeditString.length(); } } // If there is any visible selection so far, then test if there is an // intersection with the area to be painted. if (bAnySelection) { // Don't care if the selection is not visible. - bAnySelection = (vEnd.Line >= vFirstLine) && (vStart.Line <= vLastLine); + bAnySelection = (vEnd.line >= vFirstLine) && (vStart.line <= vLastLine); if (bAnySelection) { // Transform the selection from text space into screen space vSelStart = edit->bufferToDisplayPos(vStart); vSelEnd = edit->bufferToDisplayPos(vEnd); if (edit->mInputPreeditString.length() - && vStart.Line == edit->mCaretY) { + && vStart.line == edit->mCaretY) { QString sLine = edit->lineText().left(edit->mCaretX-1) + edit->mInputPreeditString + edit->lineText().mid(edit->mCaretX-1); - vSelStart.Column = edit->charToColumn(sLine,vStart.Char); + vSelStart.Column = edit->charToColumn(sLine,vStart.ch); } if (edit->mInputPreeditString.length() - && vEnd.Line == edit->mCaretY) { + && vEnd.line == edit->mCaretY) { QString sLine = edit->lineText().left(edit->mCaretX-1) + edit->mInputPreeditString + edit->lineText().mid(edit->mCaretX-1); - vSelEnd.Column = edit->charToColumn(sLine,vEnd.Char); + vSelEnd.Column = edit->charToColumn(sLine,vEnd.ch); } // In the column selection mode sort the begin and end of the selection, // this makes the painting code simpler. - if (edit->mActiveSelectionMode == SynSelectionMode::smColumn && vSelStart.Column > vSelEnd.Column) + if (edit->mActiveSelectionMode == SynSelectionMode::Column && vSelStart.Column > vSelEnd.Column) std::swap(vSelStart.Column, vSelEnd.Column); } } @@ -821,8 +821,8 @@ void SynEditTextPainter::PaintLines() // Get the line. sLine = edit->mDocument->getString(vLine - 1); // determine whether will be painted with ActiveLineColor - if (edit->mActiveSelectionMode == SynSelectionMode::smColumn) { - bCurrentLine = (vLine >= selectionBegin.Line && vLine <= selectionEnd.Line); + if (edit->mActiveSelectionMode == SynSelectionMode::Column) { + bCurrentLine = (vLine >= selectionBegin.line && vLine <= selectionEnd.line); } else { bCurrentLine = (edit->mCaretY == vLine); } @@ -859,8 +859,8 @@ void SynEditTextPainter::PaintLines() // selection mode and a good start for the smNormal mode. nLineSelStart = FirstCol; nLineSelEnd = LastCol + 1; - if ((edit->mActiveSelectionMode == SynSelectionMode::smColumn) || - ((edit->mActiveSelectionMode == SynSelectionMode::smNormal) && (cRow == vSelStart.Row)) ) { + if ((edit->mActiveSelectionMode == SynSelectionMode::Column) || + ((edit->mActiveSelectionMode == SynSelectionMode::Normal) && (cRow == vSelStart.Row)) ) { int ch = edit->columnToChar(vLine,vSelStart.Column); ch = edit->charToColumn(vLine,ch); if (ch > LastCol) { @@ -871,8 +871,8 @@ void SynEditTextPainter::PaintLines() bComplexLine = true; } } - if ( (edit->mActiveSelectionMode == SynSelectionMode::smColumn) || - ((edit->mActiveSelectionMode == SynSelectionMode::smNormal) && (cRow == vSelEnd.Row)) ) { + if ( (edit->mActiveSelectionMode == SynSelectionMode::Column) || + ((edit->mActiveSelectionMode == SynSelectionMode::Normal) && (cRow == vSelEnd.Row)) ) { int ch = edit->columnToChar(vLine,vSelEnd.Column); int col = edit->charToColumn(vLine,ch); if (col -ContentsCoord::ContentsCoord(const SynEdit *edit, int ch, int line) -{ - Q_ASSERT(edit!=nullptr); - mEdit = edit; - mChar = ch; - mLine = line; - normalize(); -} - -void ContentsCoord::normalize() -{ - if (mEdit->document()->count()==0) { - mChar = 0; - mLine = 0; - return; - } - int aLine = mLine; - int aChar = mChar; - int line = aLine-1; - int lineCount = mEdit->document()->count(); - if (line>=lineCount) { - mChar = mEdit->document()->getString(lineCount-1).length()+1; - mLine = lineCount; - return; - } - if (line<0) { - mChar = 0; - mLine = 0; - return; - } - if (aChar<1) { - while (true) { - line--; - if (line < 0) { - mChar = 0; - mLine = 0; - return; - } - QString s = mEdit->document()->getString(line); - int len = s.length(); - aChar+=len+1; - if (aChar>=1) { - break; - } - } - } else { - while (true) { - QString s =mEdit->document()->getString(line); - int len = s.length(); - if (aChar<=len+1) { - break; - } - if (line == lineCount-1) { - mChar = 1; - mLine = lineCount+1; - return; - } - aChar -= len+1; - line++; - } - } - mChar = aChar; - mLine = line+1; - return; -} - -int ContentsCoord::line() const -{ - return mLine; -} - -void ContentsCoord::setLine(int newLine) -{ - mLine = newLine; -} - -bool ContentsCoord::atStart() -{ - return mLine<1; -} - -bool ContentsCoord::atEnd() -{ - Q_ASSERT(mEdit!=nullptr); - return mLine>mEdit->document()->count(); -} - -const SynEdit *ContentsCoord::edit() const -{ - return mEdit; -} - -const ContentsCoord &ContentsCoord::operator=(const ContentsCoord &coord) -{ - mEdit = coord.mEdit; - mChar = coord.mChar; - mLine = coord.mLine; - return *this; -} - -const ContentsCoord &ContentsCoord::operator=(const ContentsCoord &&coord) -{ - if (this!=&coord) { - mEdit = coord.mEdit; - mChar = coord.mChar; - mLine = coord.mLine; - } - return *this; -} - -bool ContentsCoord::operator==(const ContentsCoord &coord) const -{ - Q_ASSERT(mEdit == coord.mEdit); - return (mLine == coord.mLine) - && (mChar == coord.mChar); -} - -bool ContentsCoord::operator<(const ContentsCoord &coord) const -{ - Q_ASSERT(mEdit == coord.mEdit); - return (mLine < coord.mLine) || (mLine == coord.mLine && mChar < coord.mChar); -} - -bool ContentsCoord::operator<=(const ContentsCoord &coord) const -{ - Q_ASSERT(mEdit == coord.mEdit); - return (mLine < coord.mLine) || (mLine == coord.mLine && mChar <= coord.mChar); -} - -bool ContentsCoord::operator>(const ContentsCoord &coord) const -{ - Q_ASSERT(mEdit == coord.mEdit); - return (mLine > coord.mLine) || (mLine == coord.mLine && mChar > coord.mChar); -} - -bool ContentsCoord::operator>=(const ContentsCoord &coord) const -{ - Q_ASSERT(mEdit == coord.mEdit); - return (mLine > coord.mLine) || (mLine == coord.mLine && mChar >= coord.mChar); -} - -size_t ContentsCoord::operator-(const ContentsCoord& coord) const -{ - Q_ASSERT(mEdit == coord.mEdit); - if (mLine == coord.mLine) { - return mChar - coord.mChar; - } else if (mLine > coord.mLine) { - size_t result = mEdit->document()->getString(coord.mLine-1).length()+1-coord.mChar; - int line = coord.mLine+1; - while (line<=mLine-1) { - result += mEdit->document()->getString(line-1).length()+1; - line++; - } - if (mLine<=mEdit->document()->count()) { - result += mChar; - } - return result; - } else { - return coord - (*this); - } -} - -const ContentsCoord &ContentsCoord::operator+=(int delta) -{ - mChar+=delta; - normalize(); - return *this; -} - -const ContentsCoord &ContentsCoord::operator-=(int delta) -{ - mChar-=delta; - normalize(); - return *this; -} - -BufferCoord ContentsCoord::toBufferCoord() const -{ - return BufferCoord{mChar,mLine}; -} - -ContentsCoord ContentsCoord::operator-(int delta) const -{ - Q_ASSERT(mEdit != nullptr); - return ContentsCoord(mEdit,mChar-delta,mLine); -} - -ContentsCoord ContentsCoord::operator+(int delta) const -{ - Q_ASSERT(mEdit != nullptr); - return ContentsCoord(mEdit,mChar+delta,mLine); -} - -QChar ContentsCoord::operator*() const -{ - Q_ASSERT(mEdit != nullptr); - if (mLine < 1) { - return QChar('\0'); - } - if (mLine > mEdit->document()->count()) { - return QChar('\0'); - } - QString s = mEdit->document()->getString(mLine-1); - if (mChar >= s.length()+1 ) { - return QChar('\n'); - } - //qDebug()<=(const BufferCoord &coord) { - return (Line > coord.Line) - || (Line == coord.Line && Char >= coord.Char); + return (line > coord.line) + || (line == coord.line && ch >= coord.ch); } bool BufferCoord::operator>(const BufferCoord &coord) { - return (Line > coord.Line) - || (Line == coord.Line && Char > coord.Char); + return (line > coord.line) + || (line == coord.line && ch > coord.ch); } bool BufferCoord::operator<(const BufferCoord &coord) { - return (Line < coord.Line) - || (Line == coord.Line && Char < coord.Char); + return (line < coord.line) + || (line == coord.line && ch < coord.ch); } bool BufferCoord::operator<=(const BufferCoord &coord) { - return (Line < coord.Line) - || (Line == coord.Line && Char <= coord.Char); + return (line < coord.line) + || (line == coord.line && ch <= coord.ch); } bool BufferCoord::operator!=(const BufferCoord &coord) { - return coord.Char != Char || coord.Line != Line; + return coord.ch != ch || coord.line != line; } diff --git a/RedPandaIDE/qsynedit/Types.h b/RedPandaIDE/qsynedit/Types.h index f44ada29..d8f11174 100644 --- a/RedPandaIDE/qsynedit/Types.h +++ b/RedPandaIDE/qsynedit/Types.h @@ -22,11 +22,11 @@ #include #include -enum class SynSelectionMode {smNormal, smLine, smColumn}; +enum class SynSelectionMode {Normal, Line, Column}; struct BufferCoord { - int Char; - int Line; + int ch; + int line; bool operator==(const BufferCoord& coord); bool operator>=(const BufferCoord& coord); bool operator>(const BufferCoord& coord); @@ -35,50 +35,6 @@ struct BufferCoord { bool operator!=(const BufferCoord& coord); }; -class SynEdit; -/** - * Nomalized buffer posistion: - * (0,0) means at the start of the file ('\0') - * (1,count of lines+1) means at the end of the file ('\0') - * (length of the line+1, line) means at the line break of the line ('\n') - */ - -class ContentsCoord { -public: - ContentsCoord(); - ContentsCoord(const ContentsCoord& coord); - int ch() const; - void setCh(int newChar); - - int line() const; - void setLine(int newLine); - bool atStart(); - bool atEnd(); - const SynEdit *edit() const; - const ContentsCoord& operator=(const ContentsCoord& coord); - const ContentsCoord& operator=(const ContentsCoord&& coord); - bool operator==(const ContentsCoord& coord) const; - bool operator<(const ContentsCoord& coord) const; - bool operator<=(const ContentsCoord& coord) const; - bool operator>(const ContentsCoord& coord) const; - bool operator>=(const ContentsCoord& coord) const; - size_t operator-(const ContentsCoord& coord) const; - const ContentsCoord& operator+=(int delta); - const ContentsCoord& operator-=(int delta); - ContentsCoord operator+(int delta) const; - ContentsCoord operator-(int delta) const; - BufferCoord toBufferCoord() const; - QChar operator*() const; -private: - ContentsCoord(const SynEdit* edit, int ch, int line); - void normalize(); -private: - int mChar; - int mLine; - const SynEdit* mEdit; - friend class SynEdit; -}; - struct DisplayCoord { int Column; int Row; diff --git a/RedPandaIDE/qsynedit/exporter/synexporter.cpp b/RedPandaIDE/qsynedit/exporter/synexporter.cpp index 8bc645f4..90ce6d32 100644 --- a/RedPandaIDE/qsynedit/exporter/synexporter.cpp +++ b/RedPandaIDE/qsynedit/exporter/synexporter.cpp @@ -63,24 +63,24 @@ void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoor // abort if not all necessary conditions are met if (!ALines || !mHighlighter || (ALines->count() == 0)) return; - Stop.Line = std::max(1, std::min(Stop.Line, ALines->count())); - Stop.Char = std::max(1, std::min(Stop.Char, ALines->getString(Stop.Line - 1).length() + 1)); - Start.Line = std::max(1, std::min(Start.Line, ALines->count())); - Start.Char = std::max(1, std::min(Start.Char, ALines->getString(Start.Line - 1).length() + 1)); - if ( (Start.Line > ALines->count()) || (Start.Line > Stop.Line) ) + Stop.line = std::max(1, std::min(Stop.line, ALines->count())); + Stop.ch = std::max(1, std::min(Stop.ch, ALines->getString(Stop.line - 1).length() + 1)); + Start.line = std::max(1, std::min(Start.line, ALines->count())); + Start.ch = std::max(1, std::min(Start.ch, ALines->getString(Start.line - 1).length() + 1)); + if ( (Start.line > ALines->count()) || (Start.line > Stop.line) ) return; - if ((Start.Line == Stop.Line) && (Start.Char >= Stop.Char)) + if ((Start.line == Stop.line) && (Start.ch >= Stop.ch)) return; // initialization mBuffer.clear(); // export all the lines into fBuffer mFirstAttribute = true; - if (Start.Line == 1) + if (Start.line == 1) mHighlighter->resetState(); else - mHighlighter->setState(ALines->ranges(Start.Line-2)); - for (int i = Start.Line; i<=Stop.Line; i++) { + mHighlighter->setState(ALines->ranges(Start.line-2)); + for (int i = Start.line; i<=Stop.line; i++) { QString Line = ALines->getString(i-1); // order is important, since Start.Y might be equal to Stop.Y // if (i == Stop.Line) @@ -93,19 +93,19 @@ void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoor PSynHighlighterAttribute attri = mHighlighter->getTokenAttribute(); int startPos = mHighlighter->getTokenPos(); QString token = mHighlighter->getToken(); - if (i==Start.Line && (startPos+token.length() < Start.Char)) { + if (i==Start.line && (startPos+token.length() < Start.ch)) { mHighlighter->next(); continue; } - if (i==Stop.Line && (startPos >= Stop.Char-1)) { + if (i==Stop.line && (startPos >= Stop.ch-1)) { mHighlighter->next(); continue; } - if (i==Stop.Line && (startPos+token.length() > Stop.Char)) { - token = token.remove(Stop.Char - startPos - 1); + if (i==Stop.line && (startPos+token.length() > Stop.ch)) { + token = token.remove(Stop.ch - startPos - 1); } - if (i==Start.Line && startPos < Start.Char-1) { - token = token.mid(Start.Char-1-startPos); + if (i==Start.line && startPos < Start.ch-1) { + token = token.mid(Start.ch-1-startPos); } QString Token = ReplaceReservedChars(token); @@ -115,7 +115,7 @@ void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoor FormatToken(Token); mHighlighter->next(); } - if (i!=Stop.Line) + if (i!=Stop.line) FormatNewLine(); } if (!mFirstAttribute) diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index f1ad48a1..ecea7fc3 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -1374,7 +1374,6 @@ void Settings::Editor::doLoad() mAutoDetectFileEncoding = boolValue("auto_detect_file_encoding",true); mUndoLimit = intValue("undo_limit",0); - //tooltips mEnableTooltips = boolValue("enable_tooltips",true); mEnableDebugTooltips = boolValue("enable_debug_tooltips",true);