diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index b9d4f5e4..bfa4e0ff 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -202,15 +202,15 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile( Editor editor(nullptr); if (pMainWindow->editorList()->getContentFromOpenedEditor( filename,buffer)){ - editor.lines()->setContents(buffer); + editor.document()->setContents(buffer); } else { QByteArray encoding; - editor.lines()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding); + editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding); } editor.setHighlighter(HighlighterManager().getCppHighlighter()); int posY = 0; - while (posY < editor.lines()->count()) { - QString line = editor.lines()->getString(posY); + while (posY < editor.document()->count()) { + QString line = editor.document()->getString(posY); if (line.isEmpty()) { posY++; continue; @@ -220,7 +220,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile( editor.highlighter()->resetState(); } else { editor.highlighter()->setState( - editor.lines()->ranges(posY-1)); + editor.document()->ranges(posY-1)); } editor.highlighter()->setLine(line,posY); while (!editor.highlighter()->eol()) { @@ -266,22 +266,22 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & Editor editor(nullptr); if (pMainWindow->editorList()->getContentFromOpenedEditor( filename,buffer)){ - editor.lines()->setContents(buffer); + editor.document()->setContents(buffer); } else { QByteArray encoding; - editor.lines()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding); + editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding); } QStringList newContents; editor.setHighlighter(HighlighterManager().getCppHighlighter()); int posY = 0; - while (posY < editor.lines()->count()) { - QString line = editor.lines()->getString(posY); + while (posY < editor.document()->count()) { + QString line = editor.document()->getString(posY); if (posY == 0) { editor.highlighter()->resetState(); } else { editor.highlighter()->setState( - editor.lines()->ranges(posY-1)); + editor.document()->ranges(posY-1)); } editor.highlighter()->setLine(line,posY); QString newLine; @@ -318,7 +318,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & } else { QByteArray realEncoding; QFile file(filename); - editor.lines()->saveToFile(file,ENCODING_AUTO_DETECT, + editor.document()->saveToFile(file,ENCODING_AUTO_DETECT, pSettings->editor().defaultEncoding(), realEncoding); } diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 5c6e2150..dfcde216 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -201,10 +201,10 @@ Editor::~Editor() { void Editor::loadFile(QString filename) { if (filename.isEmpty()) { - this->lines()->loadFromFile(mFilename,mEncodingOption,mFileEncoding); + this->document()->loadFromFile(mFilename,mEncodingOption,mFileEncoding); } else { filename = QFileInfo(filename).absoluteFilePath(); - this->lines()->loadFromFile(filename,mEncodingOption,mFileEncoding); + this->document()->loadFromFile(filename,mEncodingOption,mFileEncoding); } //this->setModified(false); updateCaption(); @@ -234,7 +234,7 @@ void Editor::saveFile(QString filename) { QByteArray encoding = mFileEncoding; if (mEncodingOption!=ENCODING_AUTO_DETECT || mFileEncoding==ENCODING_ASCII) encoding = mEncodingOption; - this->lines()->saveToFile(file,encoding, + this->document()->saveToFile(file,encoding, pSettings->editor().defaultEncoding(), mFileEncoding); emit fileSaved(filename, mInProject); @@ -642,16 +642,16 @@ void Editor::keyPressEvent(QKeyEvent *event) } else if (highlighter() && caretY()>=2 && highlighter()->isLastLineCommentNotFinished( - lines()->ranges(caretY()-2).state)) { + document()->ranges(caretY()-2).state)) { s=trimLeft(lineText()); if (s.startsWith("* ")) { handled = true; - int right = lines()->getString(caretY()-1).length()-caretX(); + int right = document()->getString(caretY()-1).length()-caretX(); s=lineBreak()+"* "; insertString(s,false); BufferCoord p = caretXY(); p.Line++; - p.Char = lines()->getString(p.Line-1).length()+1; + p.Char = document()->getString(p.Line-1).length()+1; if (right>0) { p.Char -=right+1; } @@ -924,7 +924,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to return; if (mParser && mParser->enabled() && highlighter() && (attr == highlighter()->identifierAttribute()) - && !mParser->isIncludeLine(lines()->getString(line-1)) ) { + && !mParser->isIncludeLine(document()->getString(line-1)) ) { BufferCoord p{aChar,line}; // BufferCoord pBeginPos,pEndPos; @@ -943,8 +943,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); if ((pEndPos.Line>=1) && (pEndPos.Char>=0) - && (pEndPos.Char+1 < lines()->getString(pEndPos.Line-1).length()) - && (lines()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) { + && (pEndPos.Char+1 < document()->getString(pEndPos.Line-1).length()) + && (document()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) { kind = StatementKind::skFunction; } else { kind = StatementKind::skVariable; @@ -1035,7 +1035,7 @@ bool Editor::event(QEvent *event) switch (reason) { case TipType::Preprocessor: // When hovering above a preprocessor line, determine if we want to show an include or a identifier hint - s = lines()->getString(p.Line - 1); + s = document()->getString(p.Line - 1); isIncludeLine = mParser->isIncludeLine(s); if (!isIncludeLine) s = wordAtRowCol(p); @@ -1165,7 +1165,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event) BufferCoord p; if (pointToCharLine(event->pos(),p)) { - QString s = lines()->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); @@ -1304,12 +1304,12 @@ void Editor::copyToClipboard() void Editor::cutToClipboard() { if (pSettings->editor().copySizeLimit()) { - if (lines()->count() > pSettings->editor().copyLineLimits()) { + if (document()->count() > pSettings->editor().copyLineLimits()) { QMessageBox::critical(pMainWindow,tr("Error"), tr("The text to be cut exceeds count limit!")); return; } - if (lines()->getTextLength() > pSettings->editor().copyCharLimits() * 1000) { + if (document()->getTextLength() > pSettings->editor().copyCharLimits() * 1000) { QMessageBox::critical(pMainWindow,tr("Error"), tr("The text to be cut exceeds character limit!")); return; @@ -1344,7 +1344,7 @@ void Editor::copyAsHTML() )); exporter.setCreateHTMLFragment(true); - exporter.ExportRange(lines(),blockBegin(),blockEnd()); + exporter.ExportRange(document(),blockBegin(),blockEnd()); QMimeData * mimeData = new QMimeData; @@ -1379,20 +1379,20 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT int tokenKind,start; PSynHighlighterAttribute attr; PSyntaxIssueList lst; - if ((line<1) || (line>lines()->count())) + if ((line<1) || (line>document()->count())) return; pError = std::make_shared(); p.Char = startChar; p.Line = line; - if (startChar >= lines()->getString(line-1).length()) { + if (startChar >= document()->getString(line-1).length()) { start = 1; - token = lines()->getString(line-1); + token = document()->getString(line-1); } else if (endChar < 1) { if (!getHighlighterAttriAtRowColEx(p,token,tokenType,tokenKind,start,attr)) return; } else { start = startChar; - token = lines()->getString(line-1).mid(start-1,endChar-startChar); + token = document()->getString(line-1).mid(start-1,endChar-startChar); } pError->startChar = start; pError->endChar = start + token.length(); @@ -1490,8 +1490,8 @@ void Editor::onStatusChanged(SynStatusChanges changes) { if ((!changes.testFlag(SynStatusChange::scReadOnly) && !changes.testFlag(SynStatusChange::scInsertMode) - && (lines()->count()!=mLineCount) - && (lines()->count()!=0) && ((mLineCount>0) || (lines()->count()>1))) + && (document()->count()!=mLineCount) + && (document()->count()!=0) && ((mLineCount>0) || (document()->count()>1))) || (mCurrentLineModified && !changes.testFlag(SynStatusChange::scReadOnly) @@ -1506,7 +1506,7 @@ void Editor::onStatusChanged(SynStatusChanges changes) checkSyntaxInBack(); reparseTodo(); } - mLineCount = lines()->count(); + mLineCount = document()->count(); if (changes.testFlag(scModifyChanged)) { updateCaption(); } @@ -1778,15 +1778,15 @@ QStringList Editor::getExpressionAtPosition( if (!highlighter) return result; while (true) { - if (line>=lines()->count() || line<0) + if (line>=document()->count() || line<0) break; QStringList tokens; if (line==0) { highlighter->resetState(); } else { - highlighter->setState(lines()->ranges(line-1)); + highlighter->setState(document()->ranges(line-1)); } - QString sLine = lines()->getString(line); + QString sLine = document()->getString(line); highlighter->setLine(sLine,line-1); while (!highlighter->eol()) { int start = highlighter->getTokenPos(); @@ -1979,7 +1979,7 @@ QStringList Editor::getExpressionAtPosition( line--; if (line>=0) - ch = lines()->getString(line).length()+1; + ch = document()->getString(line).length()+1; } return result; } @@ -1989,7 +1989,7 @@ QString Editor::getWordForCompletionSearch(const BufferCoord &pos,bool permitTil QString result = ""; QString s; - s = lines()->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 @@ -2026,9 +2026,9 @@ bool Editor::handleSymbolCompletion(QChar key) if (highlighter()) { if (caretX() <= 1) { if (caretY()>1) { - if (highlighter()->isLastLineCommentNotFinished(lines()->ranges(caretY() - 2).state)) + if (highlighter()->isLastLineCommentNotFinished(document()->ranges(caretY() - 2).state)) return false; - if (highlighter()->isLastLineStringNotFinished(lines()->ranges(caretY() - 2).state) + if (highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state) && (key!='\"') && (key!='\'')) return false; } @@ -2172,10 +2172,10 @@ bool Editor::handleParentheseSkip() if (status != QuoteStatus::NotQuote) return false; - if (lines()->count()==0) + if (document()->count()==0) return false; if (highlighter()) { - SynRangeState lastLineState = lines()->ranges(lines()->count()-1); + SynRangeState lastLineState = document()->ranges(document()->count()-1); if (lastLineState.parenthesisLevel==0) { setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over return true; @@ -2223,10 +2223,10 @@ bool Editor::handleBracketSkip() if (getCurrentChar() != ']') return false; - if (lines()->count()==0) + if (document()->count()==0) return false; if (highlighter()) { - SynRangeState lastLineState = lines()->ranges(lines()->count()-1); + SynRangeState lastLineState = document()->ranges(document()->count()-1); if (lastLineState.bracketLevel==0) { setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over return true; @@ -2269,7 +2269,7 @@ bool Editor::handleBraceCompletion() QString s = lineText().trimmed(); int i= caretY()-2; while ((s.isEmpty()) && (i>=0)) { - s=lines()->getString(i); + s=document()->getString(i); i--; } QString text=selText(); @@ -2309,10 +2309,10 @@ bool Editor::handleBraceSkip() if (getCurrentChar() != '}') return false; - if (lines()->count()==0) + if (document()->count()==0) return false; if (highlighter()) { - SynRangeState lastLineState = lines()->ranges(lines()->count()-1); + SynRangeState lastLineState = document()->ranges(document()->count()-1); if (lastLineState.braceLevel==0) { bool oldInsertMode = insertMode(); setInsertMode(false); //set mode to overwrite @@ -2500,10 +2500,10 @@ Editor::QuoteStatus Editor::getQuoteStatus() QuoteStatus Result = QuoteStatus::NotQuote; if (!highlighter()) return Result; - if ((caretY()>1) && highlighter()->isLastLineStringNotFinished(lines()->ranges(caretY() - 2).state)) + if ((caretY()>1) && highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state)) Result = QuoteStatus::DoubleQuote; - QString Line = lines()->getString(caretY()-1); + QString Line = document()->getString(caretY()-1); int posX = caretX()-1; if (posX >= Line.length()) { posX = Line.length()-1; @@ -2794,7 +2794,7 @@ void Editor::exportAsRTF(const QString &rtfFilename) std::placeholders::_4, std::placeholders::_5 )); - exporter.ExportAll(lines()); + exporter.ExportAll(document()); exporter.SaveToFile(rtfFilename); } @@ -2819,7 +2819,7 @@ void Editor::exportAsHTML(const QString &htmlFilename) std::placeholders::_4, std::placeholders::_5 )); - exporter.ExportAll(lines()); + exporter.ExportAll(document()); exporter.SaveToFile(htmlFilename); } @@ -3009,7 +3009,7 @@ void Editor::showHeaderCompletion(bool autoComplete) bool Editor::testInFunc(int x, int y) { bool result = false; - QString s = lines()->getString(y); + QString s = document()->getString(y); int posY = y; int posX = std::min(x,s.length()-1); // x is started from 1 int bracketLevel=0; @@ -3018,7 +3018,7 @@ bool Editor::testInFunc(int x, int y) posY--; if (posY < 0) return false; - s = lines()->getString(posY); + s = document()->getString(posY); posX = s.length()-1; } if (s[posX] == '>' @@ -3321,7 +3321,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(lines()->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; @@ -3474,10 +3474,10 @@ void Editor::updateFunctionTip(bool showTip) int bracketLevel = 0; int paramsCount = 1; int currentParamPos = 1; - if (currentLine>=lines()->count()) + if (currentLine>=document()->count()) return; while (currentLine>=0) { - QString line = lines()->getString(currentLine); + QString line = document()->getString(currentLine); if (currentLine!=caretPos.Line-1) currentChar = line.length(); QStringList tokens; @@ -3486,7 +3486,7 @@ void Editor::updateFunctionTip(bool showTip) highlighter()->resetState(); else highlighter()->setState( - lines()->ranges(currentLine-1)); + document()->ranges(currentLine-1)); highlighter()->setLine(line,currentLine); while(!highlighter()->eol()) { int start = highlighter()->getTokenPos(); @@ -3578,7 +3578,7 @@ void Editor::updateFunctionTip(bool showTip) QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation); int x = pWordBegin.Char-1-1; - QString line = lines()->getString(pWordBegin.Line-1); + QString line = document()->getString(pWordBegin.Line-1); bool hasPreviousWord=false; while (x>=0) { QChar ch=line[x]; @@ -3678,7 +3678,7 @@ void Editor::popUserCodeInTabStops() tabStopBegin = mTabStopEnd + p->x; tabStopEnd = mTabStopEnd + p->endX; } else { - int n=countLeadingWhitespaceChars(lines()->getString(caretY()-1+p->y)); + int n=countLeadingWhitespaceChars(document()->getString(caretY()-1+p->y)); // qDebug()<x; tabStopBegin = n+p->x+1; tabStopEnd = n+p->endX+1; @@ -3721,8 +3721,8 @@ void Editor::onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, if (kind == StatementKind::skUnknown) { if ((pEndPos.Line>=1) && (pEndPos.Char>=0) - && (pEndPos.Char < lines()->getString(pEndPos.Line-1).length()) - && (lines()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) { + && (pEndPos.Char < document()->getString(pEndPos.Line-1).length()) + && (document()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) { kind = StatementKind::skFunction; } else { kind = StatementKind::skVariable; @@ -3908,13 +3908,13 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW { QString result = ""; QString s; - if ((p.Line<1) || (p.Line>editor->lines()->count())) { + if ((p.Line<1) || (p.Line>editor->document()->count())) { pWordBegin = p; pWordEnd = p; return ""; } - s = editor->lines()->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 @@ -4069,7 +4069,7 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW if (i<0) { line--; if (line>=1) { - s=editor->lines()->getString(line-1); + s=editor->document()->getString(line-1); i=s.length(); continue; } else @@ -4119,12 +4119,12 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW QString Editor::getPreviousWordAtPositionForSuggestion(const BufferCoord &p) { QString result; - if ((p.Line<1) || (p.Line>lines()->count())) { + if ((p.Line<1) || (p.Line>document()->count())) { return ""; } bool inFunc = testInFunc(p.Char-1,p.Line-1); - QString s = lines()->getString(p.Line - 1); + QString s = document()->getString(p.Line - 1); int wordBegin; int wordEnd = p.Char-1; if (wordEnd >= s.length()) @@ -4190,7 +4190,7 @@ void Editor::reformat() } #endif //we must remove all breakpoints and syntax issues - onLinesDeleted(1,lines()->count()); + onLinesDeleted(1,document()->count()); QByteArray content = text().toUtf8(); QStringList args = pSettings->codeFormatter().getArguments(); #ifdef Q_OS_WIN diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 7bb0546b..bc335f10 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -458,7 +458,7 @@ void MainWindow::updateEditorActions() ui->actionCopy->setEnabled(e->selAvail()); ui->actionCut->setEnabled(e->selAvail()); - ui->actionFoldAll->setEnabled(e->lines()->count()>0); + ui->actionFoldAll->setEnabled(e->document()->count()>0); ui->actionIndent->setEnabled(!e->readOnly()); ui->actionPaste->setEnabled(!e->readOnly() && !QGuiApplication::clipboard()->text().isEmpty()); @@ -469,15 +469,15 @@ void MainWindow::updateEditorActions() ui->actionExport_As_HTML->setEnabled(true); ui->actionExport_As_RTF->setEnabled(true); ui->actionPrint->setEnabled(true); - ui->actionSelectAll->setEnabled(e->lines()->count()>0); - ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0); - ui->actionUnIndent->setEnabled(!e->readOnly() && e->lines()->count()>0); - ui->actionUnfoldAll->setEnabled(e->lines()->count()>0); - ui->actionDelete_Line->setEnabled(!e->readOnly() && e->lines()->count()>0); - ui->actionDelete_Word->setEnabled(!e->readOnly() && e->lines()->count()>0); - ui->actionDuplicate_Line->setEnabled(!e->readOnly() && e->lines()->count()>0); - ui->actionDelete_to_BOL->setEnabled(!e->readOnly() && e->lines()->count()>0); - ui->actionDelete_to_EOL->setEnabled(!e->readOnly() && e->lines()->count()>0); + ui->actionSelectAll->setEnabled(e->document()->count()>0); + ui->actionToggleComment->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionUnIndent->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionUnfoldAll->setEnabled(e->document()->count()>0); + ui->actionDelete_Line->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionDelete_Word->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionDuplicate_Line->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionDelete_to_BOL->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionDelete_to_EOL->setEnabled(!e->readOnly() && e->document()->count()>0); ui->actionFind->setEnabled(true); ui->actionReplace->setEnabled(true); @@ -491,7 +491,7 @@ void MainWindow::updateEditorActions() ui->actionClose_All->setEnabled(true); int line = e->caretY(); - ui->actionAdd_bookmark->setEnabled(e->lines()->count()>0 && !e->hasBookmark(line)); + ui->actionAdd_bookmark->setEnabled(e->document()->count()>0 && !e->hasBookmark(line)); ui->actionRemove_Bookmark->setEnabled(e->hasBookmark(line)); ui->actionModify_Bookmark_Description->setEnabled(e->hasBookmark(line)); @@ -1033,8 +1033,8 @@ void MainWindow::updateStatusbarForLineCol(bool clear) .arg(e->caretY()) .arg(col) .arg(e->selText().length()) - .arg(e->lines()->count()) - .arg(e->lines()->getTextLength()); + .arg(e->document()->count()) + .arg(e->document()->getTextLength()); mFileInfoStatus->setText(msg); } else { mFileInfoStatus->setText(""); @@ -3941,7 +3941,7 @@ void MainWindow::onEditorContextMenu(const QPoint& pos) ui->actionLocate_in_Files_View->setEnabled(!editor->isNew()); ui->actionBreakpoint_property->setEnabled(editor->hasBreakpoint(line)); ui->actionAdd_bookmark->setEnabled( - line>=0 && editor->lines()->count()>0 + line>=0 && editor->document()->count()>0 && !editor->hasBookmark(line) ); ui->actionRemove_Bookmark->setEnabled(editor->hasBookmark(line)); @@ -4544,11 +4544,11 @@ void MainWindow::onCompileIssue(PCompileIssue issue) Editor* e = mEditorList->getOpenedEditorByFilename(issue->filename); if (e!=nullptr && (issue->line>0)) { int line = issue->line; - if (line > e->lines()->count()) + if (line > e->document()->count()) return; - int col = std::min(issue->column,e->lines()->getString(line-1).length()+1); + int col = std::min(issue->column,e->document()->getString(line-1).length()+1); if (col < 1) - col = e->lines()->getString(line-1).length()+1; + col = e->document()->getString(line-1).length()+1; e->addSyntaxIssues(line,col,issue->endColumn,issue->type,issue->description); } } @@ -6529,11 +6529,11 @@ void MainWindow::on_actionAdd_bookmark_triggered() Editor* editor = mEditorList->getEditor(); int line; if (editor && editor->pointToLine(mEditorContextMenuPos,line)) { - if (editor->lines()->count()<=0) + if (editor->document()->count()<=0) return; QString desc = QInputDialog::getText(editor,tr("Bookmark Description"), tr("Description:"),QLineEdit::Normal, - editor->lines()->getString(line-1).trimmed()); + editor->document()->getString(line-1).trimmed()); desc = desc.trimmed(); editor->addBookmark(line,desc); } diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index cc0a6c2e..0aa05cbf 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -48,18 +48,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), mPaintLock = 0; mPainterLock = 0; mPainting = false; - mLines = std::make_shared(this); - mOrigLines = mLines; - //fPlugins := TList.Create; - mMouseMoved = false; - mUndoing = false; - mLines->connect(mLines.get(), &SynEditStringList::changed, this, &SynEdit::onLinesChanged); - mLines->connect(mLines.get(), &SynEditStringList::changing, this, &SynEdit::onLinesChanging); - mLines->connect(mLines.get(), &SynEditStringList::cleared, this, &SynEdit::onLinesCleared); - mLines->connect(mLines.get(), &SynEditStringList::deleted, this, &SynEdit::onLinesDeleted); - mLines->connect(mLines.get(), &SynEditStringList::inserted, this, &SynEdit::onLinesInserted); - mLines->connect(mLines.get(), &SynEditStringList::putted, this, &SynEdit::onLinesPutted); - #ifdef Q_OS_WIN mFontDummy = QFont("Consolas",12); #elif defined(Q_OS_LINUX) @@ -67,6 +55,18 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), #else #error "Not supported!" #endif + mDocument = std::make_shared(mFontDummy, this); + mOrigLines = mDocument; + //fPlugins := TList.Create; + mMouseMoved = false; + mUndoing = false; + mDocument->connect(mDocument.get(), &SynDocument::changed, this, &SynEdit::onLinesChanged); + mDocument->connect(mDocument.get(), &SynDocument::changing, this, &SynEdit::onLinesChanging); + mDocument->connect(mDocument.get(), &SynDocument::cleared, this, &SynEdit::onLinesCleared); + mDocument->connect(mDocument.get(), &SynDocument::deleted, this, &SynEdit::onLinesDeleted); + mDocument->connect(mDocument.get(), &SynDocument::inserted, this, &SynEdit::onLinesInserted); + mDocument->connect(mDocument.get(), &SynDocument::putted, this, &SynEdit::onLinesPutted); + mFontDummy.setStyleStrategy(QFont::PreferAntialias); setFont(mFontDummy); @@ -125,7 +125,6 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), mWantReturns = true; mWantTabs = false; - mTabWidth = 4; mLeftChar = 1; mTopLine = 1; mCaretX = 1; @@ -172,10 +171,10 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent), int SynEdit::displayLineCount() const { - if (mLines->empty()) { + if (mDocument->empty()) { return 0; } - return lineToRow(mLines->count()); + return lineToRow(mDocument->count()); } DisplayCoord SynEdit::displayXY() const @@ -235,8 +234,8 @@ void SynEdit::setCaretXYEx(bool CallEnsureCursorPosVisible, BufferCoord value) if (vTriggerPaint) doOnPaintTransient(SynTransientType::ttBefore); int nMaxX; - if (value.Line > mLines->count()) - value.Line = mLines->count(); + if (value.Line > mDocument->count()) + value.Line = mDocument->count(); if (mActiveSelectionMode!=SynSelectionMode::smColumn) { if (value.Line < 1) { // this is just to make sure if Lines stringlist should be empty @@ -244,10 +243,10 @@ void SynEdit::setCaretXYEx(bool CallEnsureCursorPosVisible, BufferCoord value) if (!mOptions.testFlag(SynEditorOption::eoScrollPastEol)) { nMaxX = 1; } else { - nMaxX = mLines->getString(value.Line-1).length()+1; + nMaxX = mDocument->getString(value.Line-1).length()+1; } } else { - nMaxX = mLines->getString(value.Line-1).length()+1; + nMaxX = mDocument->getString(value.Line-1).length()+1; } value.Char = std::min(value.Char,nMaxX); } @@ -358,9 +357,9 @@ bool SynEdit::canRedo() const int SynEdit::maxScrollWidth() const { if (mOptions.testFlag(eoScrollPastEol)) - return std::max(mLines->lengthOfLongestLine(),1); + return std::max(mDocument->lengthOfLongestLine(),1); else - return std::max(mLines->lengthOfLongestLine()-mCharsInWindow+1, 1); + return std::max(mDocument->lengthOfLongestLine()-mCharsInWindow+1, 1); } bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &XY, QString &Token, PSynHighlighterAttribute &Attri) @@ -375,12 +374,12 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &XY, QString &Token, int PosX, PosY, endPos, Start; QString Line; PosY = XY.Line - 1; - if (mHighlighter && (PosY >= 0) && (PosY < mLines->count())) { - Line = mLines->getString(PosY); + if (mHighlighter && (PosY >= 0) && (PosY < mDocument->count())) { + Line = mDocument->getString(PosY); if (PosY == 0) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(PosY-1)); + mHighlighter->setState(mDocument->ranges(PosY-1)); } mHighlighter->setLine(Line, PosY); PosX = XY.Char; @@ -413,12 +412,12 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke int PosX, PosY, endPos; QString Line; PosY = XY.Line - 1; - if (mHighlighter && (PosY >= 0) && (PosY < mLines->count())) { - Line = mLines->getString(PosY); + if (mHighlighter && (PosY >= 0) && (PosY < mDocument->count())) { + Line = mDocument->getString(PosY); if (PosY == 0) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(PosY-1)); + mHighlighter->setState(mDocument->ranges(PosY-1)); } mHighlighter->setLine(Line, PosY); PosX = XY.Char; @@ -482,12 +481,12 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) bool isCommentOrStringOrChar; int nBrackets = sizeof(Brackets) / sizeof(QChar); - if (mLines->count()<1) + 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 = mLines->getString(APoint.Line - 1); + Line = mDocument->getString(APoint.Line - 1); if (Line.length() >= PosX ) { Test = Line[PosX-1]; // is it one of the recognized brackets? @@ -528,7 +527,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) if (PosY == 1) break; PosY--; - Line = mLines->getString(PosY - 1); + Line = mDocument->getString(PosY - 1); PosX = Line.length() + 1; } } else { @@ -561,10 +560,10 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) } } // get next line if possible - if (PosY == mLines->count()) + if (PosY == mDocument->count()) break; PosY++; - Line = mLines->getString(PosY - 1); + Line = mDocument->getString(PosY - 1); PosX = 0; } } @@ -578,12 +577,12 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) QStringList SynEdit::contents() { - return lines()->contents(); + return document()->contents(); } QString SynEdit::text() { - return lines()->text(); + return document()->text(); } bool SynEdit::getPositionOfMouse(BufferCoord &aPos) @@ -636,7 +635,7 @@ void SynEdit::invalidateGutter() void SynEdit::invalidateGutterLine(int aLine) { - if ((aLine < 1) || (aLine > mLines->count())) + if ((aLine < 1) || (aLine > mDocument->count())) return; invalidateGutterLines(aLine, aLine); @@ -659,7 +658,7 @@ void SynEdit::invalidateGutterLines(int FirstLine, int LastLine) std::swap(LastLine, FirstLine); if (mUseCodeFolding) { FirstLine = lineToRow(FirstLine); - if (LastLine <= mLines->count()) + if (LastLine <= mDocument->count()) LastLine = lineToRow(LastLine); else LastLine = INT_MAX; @@ -721,7 +720,7 @@ DisplayCoord SynEdit::bufferToDisplayPos(const BufferCoord &p) const { DisplayCoord result {p.Char,p.Line}; // Account for tabs and charColumns - if (p.Line-1 count()) + if (p.Line-1 count()) result.Column = charToColumn(p.Line,p.Char); // Account for code folding if (mUseCodeFolding) @@ -741,7 +740,7 @@ BufferCoord SynEdit::displayToBufferPos(const DisplayCoord &p) const if (mUseCodeFolding) Result.Line = foldRowToLine(p.Row); // Account for tabs - if (Result.Line <= mLines->count() ) { + if (Result.Line <= mDocument->count() ) { Result.Char = columnToChar(Result.Line,p.Column); } return Result; @@ -760,18 +759,18 @@ ContentsCoord SynEdit::createNormalizedBufferCoord(int aChar, int aLine) const QStringList SynEdit::getContents(const ContentsCoord &pStart, const ContentsCoord &pEnd) { QStringList result; - if (mLines->count()==0) + if (mDocument->count()==0) return result; if (pStart.line()>0) { - QString s = mLines->getString(pStart.line()-1); + QString s = mDocument->getString(pStart.line()-1); result += s.mid(pStart.ch()-1); } - int endLine = std::min(pEnd.line(),mLines->count()); + int endLine = std::min(pEnd.line(),mDocument->count()); for (int i=pStart.line();igetString(i); + result += mDocument->getString(i); } - if (pEnd.line()<=mLines->count()) { - result += mLines->getString(pEnd.line()-1).mid(0,pEnd.ch()-1); + if (pEnd.line()<=mDocument->count()) { + result += mDocument->getString(pEnd.line()-1).mid(0,pEnd.ch()-1); } return result; } @@ -787,7 +786,7 @@ int SynEdit::leftSpaces(const QString &line) const if (mOptions.testFlag(eoAutoIndent)) { for (QChar ch:line) { if (ch == '\t') { - result += mTabWidth - (result % mTabWidth); + result += tabWidth() - (result % tabWidth()); } else if (ch == ' ') { result ++; } else { @@ -800,8 +799,8 @@ int SynEdit::leftSpaces(const QString &line) const QString SynEdit::GetLeftSpacing(int charCount, bool wantTabs) const { - if (wantTabs && !mOptions.testFlag(eoTabsToSpaces)) { - return QString(charCount / mTabWidth,'\t') + QString(charCount % mTabWidth,' '); + if (wantTabs && !mOptions.testFlag(eoTabsToSpaces) && tabWidth()>0) { + return QString(charCount / tabWidth(),'\t') + QString(charCount % tabWidth(),' '); } else { return QString(charCount,' '); } @@ -809,8 +808,8 @@ QString SynEdit::GetLeftSpacing(int charCount, bool wantTabs) const int SynEdit::charToColumn(int aLine, int aChar) const { - if (aLine>=1 && aLine <= mLines->count()) { - QString s = mLines->getString(aLine - 1); + if (aLine>=1 && aLine <= mDocument->count()) { + QString s = mDocument->getString(aLine - 1); return charToColumn(s,aChar); } return aChar; @@ -822,7 +821,7 @@ int SynEdit::charToColumn(const QString &s, int aChar) const int len = std::min(aChar-1,s.length()); for (int i=0;icount()) && (aLine >= 1)); - if (aLine <= mLines->count()) { - QString s = mLines->getString(aLine - 1); + Q_ASSERT( (aLine <= mDocument->count()) && (aLine >= 1)); + if (aLine <= mDocument->count()) { + QString s = mDocument->getString(aLine - 1); int x = 0; int len = s.length(); int i; for (i=0;i=aColumn) { @@ -853,18 +852,7 @@ int SynEdit::columnToChar(int aLine, int aColumn) const int SynEdit::stringColumns(const QString &line, int colsBefore) const { - int columns = std::max(0,colsBefore); - int charCols; - for (int i=0;istringColumns(line,colsBefore); } int SynEdit::getLineIndent(const QString &line) const @@ -873,7 +861,7 @@ int SynEdit::getLineIndent(const QString &line) const for (QChar ch:line) { switch(ch.unicode()) { case '\t': - indents+=mTabWidth; + indents+=tabWidth(); break; case ' ': indents+=1; @@ -943,7 +931,7 @@ void SynEdit::invalidateLine(int Line) QRect rcInval; if (mPainterLock >0) return; - if (Line<1 || (Line>mLines->count() && + if (Line<1 || (Line>mDocument->count() && Line!=1) || !isVisible()) return; @@ -984,14 +972,14 @@ void SynEdit::invalidateLines(int FirstLine, int LastLine) if (LastLine < FirstLine) std::swap(LastLine, FirstLine); - if (LastLine >= mLines->count()) + if (LastLine >= mDocument->count()) LastLine = INT_MAX; // paint empty space beyond last line if (mUseCodeFolding) { FirstLine = lineToRow(FirstLine); // Could avoid this conversion if (First = Last) and // (Length < CharsInWindow) but the dependency isn't worth IMO. - if (LastLine < mLines->count()) + if (LastLine < mDocument->count()) LastLine = lineToRow(LastLine + 1) - 1; } @@ -1066,8 +1054,8 @@ QString SynEdit::wordAtCursor() QString SynEdit::wordAtRowCol(const BufferCoord &pos) { - if ((pos.Line >= 1) && (pos.Line <= mLines->count())) { - QString line = mLines->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 ""; @@ -1093,8 +1081,8 @@ QString SynEdit::wordAtRowCol(const BufferCoord &pos) QChar SynEdit::charAt(const BufferCoord &pos) { - if ((pos.Line >= 1) && (pos.Line <= mLines->count())) { - QString line = mLines->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); @@ -1109,7 +1097,7 @@ QChar SynEdit::nextNotspaceChar(int line, int ch) { if (ch<0) return QChar(); - QString s = mLines->getString(line); + QString s = mDocument->getString(line); if (s.isEmpty()) return QChar(); int x=ch; @@ -1187,7 +1175,7 @@ void SynEdit::processGutterClick(QMouseEvent *event) } // If not, check gutter marks - if (Line>=1 && Line <= mLines->count()) { + if (Line>=1 && Line <= mDocument->count()) { emit gutterClicked(event->button(),X,Y,Line); } } @@ -1201,10 +1189,10 @@ void SynEdit::clearUndo() int SynEdit::findIndentsStartLine(int line, QVector indents) { line--; - if (line<0 || line>=mLines->count()) + if (line<0 || line>=mDocument->count()) return -1; while (line>=1) { - SynRangeState range = mLines->ranges(line); + SynRangeState range = mDocument->ranges(line); QVector newIndents = range.indents.mid(range.firstIndentThisLine); int i = 0; int len = indents.length(); @@ -1243,7 +1231,7 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y) PosY--; if (PosY<1 ) return Result; - QString Line = mLines->getString(PosY - 1); + QString Line = mDocument->getString(PosY - 1); if ((PosX > Line.length()) || (PosX<1)) PosX = Line.length(); int numBrackets = 1; @@ -1252,7 +1240,7 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y) PosY--; if (PosY<1) return Result; - Line = mLines->getString(PosY - 1); + Line = mDocument->getString(PosY - 1); PosX = Line.length(); continue; } @@ -1280,7 +1268,7 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y) PosY--; if (PosY<1) return Result; - Line = mLines->getString(PosY - 1); + Line = mDocument->getString(PosY - 1); PosX = Line.length(); } } @@ -1288,10 +1276,7 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y) int SynEdit::charColumns(QChar ch) const { - if (ch.unicode()<=32) - return 1; - //return std::ceil((int)(fontMetrics().horizontalAdvance(ch) * dpiFactor()) / (double)mCharWidth); - return std::ceil((int)(fontMetrics().horizontalAdvance(ch)) / (double)mCharWidth); + return mDocument->charColumns(ch); } void SynEdit::showCaret() @@ -1344,13 +1329,13 @@ BufferCoord SynEdit::nextWordPosEx(const BufferCoord &XY) int CX = XY.Char; int CY = XY.Line; // valid line? - if ((CY >= 1) && (CY <= mLines->count())) { - QString Line = mLines->getString(CY - 1); + if ((CY >= 1) && (CY <= mDocument->count())) { + QString Line = mDocument->getString(CY - 1); int LineLen = Line.length(); if (CX >= LineLen) { // find first IdentChar or multibyte char in the next line - if (CY < mLines->count()) { - Line = mLines->getString(CY); + if (CY < mDocument->count()) { + Line = mDocument->getString(CY); CY++; CX=StrScanForWordChar(Line,1); if (CX==0) @@ -1365,8 +1350,8 @@ BufferCoord SynEdit::nextWordPosEx(const BufferCoord &XY) CX = StrScanForWordChar(Line, CX); // if one of those failed position at the begin of next line if (CX == 0) { - if (CY < mLines->count()) { - Line = mLines->getString(CY); + if (CY < mDocument->count()) { + Line = mDocument->getString(CY); CY++; CX=StrScanForWordChar(Line,1); if (CX==0) @@ -1390,8 +1375,8 @@ BufferCoord SynEdit::wordStartEx(const BufferCoord &XY) int CX = XY.Char; int CY = XY.Line; // valid line? - if ((CY >= 1) && (CY <= mLines->count())) { - QString Line = mLines->getString(CY - 1); + if ((CY >= 1) && (CY <= mDocument->count())) { + QString Line = mDocument->getString(CY - 1); CX = std::min(CX, Line.length()+1); if (CX > 1) { if (isWordChar(Line[CX - 2])) @@ -1411,8 +1396,8 @@ BufferCoord SynEdit::wordEndEx(const BufferCoord &XY) int CX = XY.Char; int CY = XY.Line; // valid line? - if ((CY >= 1) && (CY <= mLines->count())) { - QString Line = mLines->getString(CY - 1); + if ((CY >= 1) && (CY <= mDocument->count())) { + QString Line = mDocument->getString(CY - 1); if (CX <= Line.length() && CX-1>=0) { if (isWordChar(Line[CX - 1])) CX = StrScanForNonWordChar(Line, CX); @@ -1433,14 +1418,14 @@ BufferCoord SynEdit::prevWordPosEx(const BufferCoord &XY) int CX = XY.Char; int CY = XY.Line; // valid line? - if ((CY >= 1) && (CY <= mLines->count())) { - QString Line = mLines->getString(CY - 1); + if ((CY >= 1) && (CY <= mDocument->count())) { + QString Line = mDocument->getString(CY - 1); CX = std::min(CX, Line.length()); if (CX <= 1) { // find last IdentChar in the previous line if (CY > 1) { CY -- ; - Line = mLines->getString(CY - 1); + Line = mDocument->getString(CY - 1); CX = StrRScanForWordChar(Line, Line.length())+1; } } else { @@ -1453,7 +1438,7 @@ BufferCoord SynEdit::prevWordPosEx(const BufferCoord &XY) // find last IdentChar in the previous line if (CY > 1) { CY -- ; - Line = mLines->getString(CY - 1); + Line = mDocument->getString(CY - 1); CX = StrRScanForWordChar(Line, Line.length())+1; } else { CX = 1; @@ -1475,9 +1460,9 @@ void SynEdit::setWordBlock(BufferCoord Value) // Value.Char = // else // Value.Char = std::max(Value.Char, 1); - Value.Line = minMax(Value.Line, 1, mLines->count()); + Value.Line = minMax(Value.Line, 1, mDocument->count()); Value.Char = std::max(Value.Char, 1); - QString TempString = mLines->getString(Value.Line - 1); //needed for CaretX = LineLength +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}); return; @@ -1494,7 +1479,7 @@ int SynEdit::findCommentStartLine(int searchStartLine) int commentStartLine = searchStartLine; SynRangeState range; while (commentStartLine>=1) { - range = mLines->ranges(commentStartLine-1); + range = mDocument->ranges(commentStartLine-1); if (!mHighlighter->isLastLineCommentNotFinished(range.state)){ commentStartLine++; break; @@ -1513,14 +1498,14 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) { if (!mHighlighter) return 0; - line = std::min(line, mLines->count()+1); + line = std::min(line, mDocument->count()+1); if (line<=1) return 0; // find the first non-empty preceeding line int startLine = line-1; QString startLineText; while (startLine>=1) { - startLineText = mLines->getString(startLine-1); + startLineText = mDocument->getString(startLine-1); if (!startLineText.startsWith('#') && !startLineText.trimmed().isEmpty()) { break; } @@ -1530,7 +1515,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) if (startLine>=1) { //calculate the indents of last statement; indentSpaces = leftSpaces(startLineText); - SynRangeState rangePreceeding = mLines->ranges(startLine-1); + SynRangeState rangePreceeding = mDocument->ranges(startLine-1); mHighlighter->setState(rangePreceeding); if (addIndent) { // QString trimmedS = s.trimmed(); @@ -1538,7 +1523,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) mHighlighter->setLine(trimmedLineText,line-1); int statePrePre; if (startLine>1) { - statePrePre = mLines->ranges(startLine-2).state; + statePrePre = mDocument->ranges(startLine-2).state; } else { statePrePre = 0; } @@ -1590,8 +1575,8 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) additionIndent = 1; int commentStartLine = findCommentStartLine(startLine-1); SynRangeState range; - indentSpaces = leftSpaces(mLines->getString(commentStartLine-1)); - range = mLines->ranges(commentStartLine-1); + indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1)); + range = mDocument->ranges(commentStartLine-1); matchingIndents = range.matchingIndents; indentAdded = true; l = commentStartLine; @@ -1603,8 +1588,8 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) // we should use the indents of the start line of the comment int commentStartLine = findCommentStartLine(startLine-2); SynRangeState range; - indentSpaces = leftSpaces(mLines->getString(commentStartLine-1)); - range = mLines->ranges(commentStartLine-1); + indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1)); + range = mDocument->ranges(commentStartLine-1); matchingIndents = range.matchingIndents; indentAdded = true; l = commentStartLine; @@ -1618,7 +1603,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) ) { // find the indent's start line, and use it's indent as the default indent; while (l>=1) { - SynRangeState range = mLines->ranges(l-1); + SynRangeState range = mDocument->ranges(l-1); QVector newIndents = range.indents.mid(range.firstIndentThisLine); int i = 0; int len = matchingIndents.length(); @@ -1642,9 +1627,9 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) // but it's not a complete statement matchingIndents = range.matchingIndents; } else { - indentSpaces = leftSpaces(mLines->getString(l-1)); + indentSpaces = leftSpaces(mDocument->getString(l-1)); if (newIndents.length()>0) - indentSpaces+=mTabWidth; + indentSpaces+=tabWidth(); break; } } else { @@ -1655,7 +1640,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) } if (!indentAdded) { if (rangePreceeding.firstIndentThisLine < rangePreceeding.indents.length()) { - indentSpaces += mTabWidth; + indentSpaces += tabWidth(); indentAdded = true; } } @@ -1665,11 +1650,11 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) QString token; PSynHighlighterAttribute attr; coord.Line = startLine; - coord.Char = lines()->getString(startLine-1).length(); + coord.Char = document()->getString(startLine-1).length(); if (getHighlighterAttriAtRowCol(coord,token,attr) && attr == mHighlighter->symbolAttribute() && token == ":") { - indentSpaces += mTabWidth; + indentSpaces += tabWidth(); indentAdded = true; } } @@ -1683,11 +1668,11 @@ void SynEdit::doSelectAll() { BufferCoord LastPt; LastPt.Char = 1; - if (mLines->empty()) { + if (mDocument->empty()) { LastPt.Line = 1; } else { - LastPt.Line = mLines->count(); - LastPt.Char = mLines->getString(LastPt.Line-1).length()+1; + LastPt.Line = mDocument->count(); + LastPt.Char = mDocument->getString(LastPt.Line-1).length()+1; } setCaretAndSelection(caretXY(), BufferCoord{1, 1}, LastPt); // Selection should have changed... @@ -1714,7 +1699,7 @@ void SynEdit::doComment() else endLine = origBlockEnd.Line - 1; for (int i = origBlockBegin.Line - 1; i<=endLine; i++) { - mLines->putString(i, "//" + mLines->getString(i)); + mDocument->putString(i, "//" + mDocument->getString(i)); mUndoList->AddChange(SynChangeReason::crInsert, BufferCoord{1, i + 1}, BufferCoord{3, i + 1}, @@ -1758,14 +1743,14 @@ void SynEdit::doUncomment() else endLine = origBlockEnd.Line - 1; for (int i = origBlockBegin.Line - 1; i<= endLine; i++) { - s = mLines->getString(i); + s = mDocument->getString(i); // Find // after blanks only int j = 0; while ((j+1 < s.length()) && (s[j] == '\n' || s[j] == '\t')) j++; if ((j + 1 < s.length()) && (s[j] == '/') && (s[j + 1] == '/')) { s.remove(j,2); - mLines->putString(i,s); + mDocument->putString(i,s); mUndoList->AddChange(SynChangeReason::crDelete, BufferCoord{j+1, i + 1}, BufferCoord{j + 3, i + 1}, @@ -1811,7 +1796,7 @@ void SynEdit::doToggleComment() else endLine = origBlockEnd.Line - 1; for (int i = origBlockBegin.Line - 1; i<= endLine; i++) { - s = mLines->getString(i); + s = mDocument->getString(i); // Find // after blanks only int j = 0; while ((j < s.length()) && (s[j] == '\n' || s[j] == '\t')) @@ -1985,8 +1970,8 @@ void SynEdit::doDeleteLastChar() // join this line with the last line if possible if (mCaretY > 1) { internalSetCaretY(mCaretY - 1); - internalSetCaretX(mLines->getString(mCaretY - 1).length() + 1); - mLines->deleteAt(mCaretY); + internalSetCaretX(mDocument->getString(mCaretY - 1).length() + 1); + mDocument->deleteAt(mCaretY); doLinesDeleted(mCaretY+1, 1); if (mOptions.testFlag(eoTrimTrailingSpaces)) Temp = trimRight(Temp); @@ -2021,10 +2006,10 @@ void SynEdit::doDeleteLastChar() // } else { //how much till the next tab column - int BackCounter = (caretColumn - 1) % mTabWidth; + int BackCounter = (caretColumn - 1) % tabWidth(); if (BackCounter == 0) - BackCounter = mTabWidth; - SpaceCount2 = std::max(0,SpaceCount1 - mTabWidth); + BackCounter = tabWidth(); + SpaceCount2 = std::max(0,SpaceCount1 - tabWidth()); newCaretX = columnToChar(mCaretY,SpaceCount2+1); helper = Temp.mid(newCaretX - 1, mCaretX - newCaretX); Temp.remove(newCaretX-1,mCaretX - newCaretX); @@ -2088,12 +2073,12 @@ void SynEdit::doDeleteCurrentChar() properSetLine(mCaretY - 1, Temp); } else { // join line with the line after - if (mCaretY < mLines->count()) { - properSetLine(mCaretY - 1, Temp + mLines->getString(mCaretY)); + if (mCaretY < mDocument->count()) { + properSetLine(mCaretY - 1, Temp + mDocument->getString(mCaretY)); Caret.Char = 1; Caret.Line = mCaretY + 1; helper = lineBreak(); - mLines->deleteAt(mCaretY); + mDocument->deleteAt(mCaretY); if (mCaretX==1) doLinesDeleted(mCaretY, 1); else @@ -2160,20 +2145,20 @@ void SynEdit::doDeleteFromBOL() void SynEdit::doDeleteLine() { - if (!mReadOnly && (mLines->count() > 0) - && ! ((mCaretY == mLines->count()) && (lineText().isEmpty()))) { + if (!mReadOnly && (mDocument->count() > 0) + && ! ((mCaretY == mDocument->count()) && (lineText().isEmpty()))) { doOnPaintTransient(SynTransientType::ttBefore); if (selAvail()) setBlockBegin(caretXY()); QString helper = lineText(); - if (mCaretY == mLines->count()) { - mLines->putString(mCaretY - 1,""); + if (mCaretY == mDocument->count()) { + mDocument->putString(mCaretY - 1,""); mUndoList->AddChange(SynChangeReason::crSilentDeleteAfterCursor, BufferCoord{1, mCaretY}, BufferCoord{helper.length() + 1, mCaretY}, helper, SynSelectionMode::smNormal); } else { - mLines->deleteAt(mCaretY - 1); + mDocument->deleteAt(mCaretY - 1); helper = helper + lineBreak(); mUndoList->AddChange(SynChangeReason::crSilentDeleteAfterCursor, BufferCoord{1, mCaretY}, @@ -2189,7 +2174,7 @@ void SynEdit::doDeleteLine() void SynEdit::doSelecteLine() { setBlockBegin(BufferCoord{1,mCaretY}); - if (mCaretY==mLines->count()) + if (mCaretY==mDocument->count()) setBlockEnd(BufferCoord{lineText().length()+1,mCaretY}); else setBlockEnd(BufferCoord{1,mCaretY+1}); @@ -2197,9 +2182,9 @@ void SynEdit::doSelecteLine() void SynEdit::doDuplicateLine() { - if (!mReadOnly && (mLines->count() > 0)) { + if (!mReadOnly && (mDocument->count() > 0)) { doOnPaintTransient(SynTransientType::ttBefore); - mLines->insert(mCaretY, lineText()); + mDocument->insert(mCaretY, lineText()); doLinesInserted(mCaretY + 1, 1); mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), "", SynSelectionMode::smNormal); @@ -2210,7 +2195,7 @@ void SynEdit::doDuplicateLine() void SynEdit::doMoveSelUp(bool addUndo) { - if (!mReadOnly && (mLines->count() > 0) && (blockBegin().Line > 1)) { + if (!mReadOnly && (mDocument->count() > 0) && (blockBegin().Line > 1)) { doOnPaintTransient(SynTransientType::ttBefore); // Backup caret and selection @@ -2232,12 +2217,12 @@ void SynEdit::doMoveSelUp(bool addUndo) mUndoList->EndBlock(); } // Delete line above selection - QString s = mLines->getString(origBlockBegin.Line - 2); // before start, 0 based - mLines->deleteAt(origBlockBegin.Line - 2); // before start, 0 based + 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 - mLines->insert(origBlockEnd.Line - 1, s); + mDocument->insert(origBlockEnd.Line - 1, s); doLinesInserted(origBlockEnd.Line, 1); // Restore caret and selection setCaretAndSelection( @@ -2252,7 +2237,7 @@ void SynEdit::doMoveSelUp(bool addUndo) void SynEdit::doMoveSelDown(bool addUndo) { - if (!mReadOnly && (mLines->count() > 0) && (blockEnd().Line < mLines->count())) { + if (!mReadOnly && (mDocument->count() > 0) && (blockEnd().Line < mDocument->count())) { doOnPaintTransient(SynTransientType::ttBefore); // Backup caret and selection BufferCoord origBlockBegin = blockBegin(); @@ -2273,12 +2258,12 @@ void SynEdit::doMoveSelDown(bool addUndo) } // Delete line below selection - QString s = mLines->getString(origBlockEnd.Line); // after end, 0 based - mLines->deleteAt(origBlockEnd.Line); // after end, 0 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 - mLines->insert(origBlockBegin.Line - 1, s); + mDocument->insert(origBlockBegin.Line - 1, s); doLinesInserted(origBlockBegin.Line, 1); // Restore caret and selection @@ -2295,7 +2280,7 @@ void SynEdit::doMoveSelDown(bool addUndo) void SynEdit::clearAll() { - mLines->clear(); + mDocument->clear(); mMarkList.clear(); mUndoList->Clear(); mRedoList->Clear(); @@ -2338,11 +2323,11 @@ void SynEdit::insertLine(bool moveCaret) if (mCaretY==1) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(mCaretY-2)); + mHighlighter->setState(mDocument->ranges(mCaretY-2)); } mHighlighter->setLine(leftLineText, mCaretY-1); mHighlighter->nextToEol(); - mLines->setRange(mCaretY-1,mHighlighter->getRangeState()); + mDocument->setRange(mCaretY-1,mHighlighter->getRangeState()); notInComment = !mHighlighter->isLastLineCommentNotFinished( mHighlighter->getRangeState().state) && !mHighlighter->isLastLineStringNotFinished( @@ -2356,7 +2341,7 @@ void SynEdit::insertLine(bool moveCaret) && notInComment); } QString indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); - mLines->insert(mCaretY, indentSpacesForRightLineText+rightLineText); + mDocument->insert(mCaretY, indentSpacesForRightLineText+rightLineText); nLinesInserted++; mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), rightLineText, @@ -2367,9 +2352,9 @@ void SynEdit::insertLine(bool moveCaret) if (!notInComment && ( leftLineText.endsWith("/*") && rightLineText.startsWith("*/") )) { - indentSpaces = calcIndentSpaces(mCaretY+1, "" , mOptions.testFlag(eoAutoIndent)) + mTabWidth; + indentSpaces = calcIndentSpaces(mCaretY+1, "" , mOptions.testFlag(eoAutoIndent)) + tabWidth(); indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); - mLines->insert(mCaretY, indentSpacesForRightLineText); + mDocument->insert(mCaretY, indentSpacesForRightLineText); nLinesInserted++; mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), "", SynSelectionMode::smNormal); @@ -2381,7 +2366,7 @@ void SynEdit::insertLine(bool moveCaret) indentSpaces = calcIndentSpaces(mCaretY+1, "" , mOptions.testFlag(eoAutoIndent) && notInComment); indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); - mLines->insert(mCaretY, indentSpacesForRightLineText); + mDocument->insert(mCaretY, indentSpacesForRightLineText); nLinesInserted++; mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), "", SynSelectionMode::smNormal); @@ -2427,7 +2412,7 @@ void SynEdit::doTabKey() int NewCaretX = 0; if (mOptions.testFlag(eoTabsToSpaces)) { int cols = charToColumn(mCaretY,mCaretX); - i = tabWidth() - (cols) % mTabWidth; + i = tabWidth() - (cols) % tabWidth(); Spaces = QString(i,' '); NewCaretX = mCaretX + i; } else { @@ -2457,7 +2442,7 @@ void SynEdit::doShiftTabKey() } //Don't un-tab if caret is not on line or is beyond line end - if (mCaretY > mLines->count() || mCaretX > lineText().length()+1) + if (mCaretY > mDocument->count() || mCaretX > lineText().length()+1) return; //Don't un-tab if no chars before the Caret if (mCaretX==1) @@ -2472,9 +2457,9 @@ void SynEdit::doShiftTabKey() NewX= mCaretX-1; } else { int colsBefore = charToColumn(mCaretY,mCaretX)-1; - int spacesToRemove = colsBefore % mTabWidth; + int spacesToRemove = colsBefore % tabWidth(); if (spacesToRemove == 0) - spacesToRemove = mTabWidth; + spacesToRemove = tabWidth(); if (spacesToRemove > colsBefore ) spacesToRemove = colsBefore; NewX = mCaretX; @@ -2516,17 +2501,17 @@ bool SynEdit::canDoBlockIndent() } - if (BB.Line > mLines->count() || BE.Line > mLines->count()) { + if (BB.Line > mDocument->count() || BE.Line > mDocument->count()) { return false; } if (mActiveSelectionMode == SynSelectionMode::smNormal) { - QString s = mLines->getString(BB.Line-1).mid(0,BB.Char-1); + QString s = mDocument->getString(BB.Line-1).mid(0,BB.Char-1); if (!s.trimmed().isEmpty()) return false; if (BE.Char>1) { - QString s1=mLines->getString(BE.Line-1).mid(BE.Char-1); - QString s2=mLines->getString(BE.Line-1).mid(0,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 (!s1.trimmed().isEmpty() && !s2.trimmed().isEmpty()) return false; } @@ -2535,7 +2520,7 @@ bool SynEdit::canDoBlockIndent() int startCol = charToColumn(BB.Line,BB.Char); int endCol = charToColumn(BE.Line,BE.Char); for (int i = BB.Line; i<=BE.Line;i++) { - QString line = mLines->getString(i-1); + QString line = mDocument->getString(i-1); int startChar = columnToChar(i,startCol); QString s = line.mid(0,startChar-1); if (!s.trimmed().isEmpty()) @@ -2564,8 +2549,8 @@ QRect SynEdit::calculateCaretRect() const } QPoint caretPos = rowColumnToPixels(coord); int caretWidth=mCharWidth; - if (mCaretY <= mLines->count() && mCaretX <= mLines->getString(mCaretY-1).length()) { - caretWidth = charColumns(mLines->getString(mCaretY-1)[mCaretX-1])*mCharWidth; + if (mCaretY <= mDocument->count() && mCaretX <= mDocument->getString(mCaretY-1).length()) { + caretWidth = charColumns(mDocument->getString(mCaretY-1)[mCaretX-1])*mCharWidth; } if (mActiveSelectionMode == SynSelectionMode::smColumn) { return QRect(caretPos.x(),caretPos.y(),caretWidth, @@ -2583,8 +2568,8 @@ QRect SynEdit::calculateInputCaretRect() const DisplayCoord coord = displayXY(); QPoint caretPos = rowColumnToPixels(coord); int caretWidth=mCharWidth; - if (mCaretY <= mLines->count() && mCaretX <= mLines->getString(mCaretY-1).length()) { - caretWidth = charColumns(mLines->getString(mCaretY-1)[mCaretX-1])*mCharWidth; + if (mCaretY <= mDocument->count() && mCaretX <= mDocument->getString(mCaretY-1).length()) { + caretWidth = charColumns(mDocument->getString(mCaretY-1)[mCaretX-1])*mCharWidth; } return QRect(caretPos.x(),caretPos.y(),caretWidth, mTextHeight); @@ -2686,12 +2671,12 @@ void SynEdit::doBlockIndent() } else { e = BE.Line; if (mOptions.testFlag(SynEditorOption::eoTabsToSpaces)) - x = caretX() + mTabWidth; + x = caretX() + tabWidth(); else x = caretX() + 1; } if (mOptions.testFlag(eoTabsToSpaces)) { - spaces = QString(mTabWidth,' ') ; + spaces = QString(tabWidth(),' ') ; } else { spaces = "\t"; } @@ -2756,7 +2741,7 @@ void SynEdit::doBlockUnindent() // build string to delete QString strToDelete; for (int i = BB.Line; i<= e;i++) { - QString line = mLines->getString(i - 1); + QString line = mDocument->getString(i - 1); if (!strToDelete.isEmpty()) strToDelete+=lineBreak(); if (line.isEmpty()) @@ -2764,7 +2749,7 @@ void SynEdit::doBlockUnindent() if (line[0]!=' ' && line[0]!='\t') continue; int charsToDelete = 0; - while (charsToDelete < mTabWidth && + while (charsToDelete < tabWidth() && charsToDelete < line.length() && line[charsToDelete] == ' ') charsToDelete++; @@ -2777,7 +2762,7 @@ void SynEdit::doBlockUnindent() if (i==oldCaretPos.Line) x = charsToDelete; QString tempString = line.mid(charsToDelete); - mLines->putString(i-1,tempString); + mDocument->putString(i-1,tempString); strToDelete += line.mid(0,charsToDelete); } mUndoList->AddChange( @@ -2837,16 +2822,16 @@ void SynEdit::doAddChar(QChar AChar) && mOptions.testFlag(eoAutoIndent) && mHighlighter && mHighlighter->getClass()==SynHighlighterClass::CppHighlighter - && (oldCaretY<=mLines->count()) ) { + && (oldCaretY<=mDocument->count()) ) { //unindent if ':' at end of the line if (AChar == ':') { - QString line = mLines->getString(oldCaretY-1); + QString line = mDocument->getString(oldCaretY-1); if (line.length() <= oldCaretX) { int indentSpaces = calcIndentSpaces(oldCaretY,line+":", true); if (indentSpaces != leftSpaces(line)) { QString newLine = GetLeftSpacing(indentSpaces,true) + trimLeft(line); - mLines->putString(oldCaretY-1,newLine); + mDocument->putString(oldCaretY-1,newLine); internalSetCaretXY(BufferCoord{newLine.length()+2,oldCaretY}); setBlockBegin(caretXY()); setBlockEnd(caretXY()); @@ -2868,14 +2853,14 @@ void SynEdit::doAddChar(QChar AChar) } } else if (AChar == '{' || AChar == '}' || AChar == '#') { //Reindent line when add '{' '}' and '#' at the beginning - QString left = mLines->getString(oldCaretY-1).mid(0,oldCaretX-1); + QString left = mDocument->getString(oldCaretY-1).mid(0,oldCaretX-1); // and the first nonblank char is this new { if (left.trimmed().isEmpty()) { int indentSpaces = calcIndentSpaces(oldCaretY,AChar, true); if (indentSpaces != leftSpaces(left)) { - QString right = mLines->getString(oldCaretY-1).mid(oldCaretX-1); + QString right = mDocument->getString(oldCaretY-1).mid(oldCaretX-1); QString newLeft = GetLeftSpacing(indentSpaces,true); - mLines->putString(oldCaretY-1,newLeft+right); + mDocument->putString(oldCaretY-1,newLeft+right); BufferCoord newCaretPos = BufferCoord{newLeft.length()+2,oldCaretY}; internalSetCaretXY(newCaretPos); setBlockBegin(caretXY()); @@ -3362,32 +3347,32 @@ int SynEdit::scanFrom(int Index, int canStopIndex) { SynRangeState iRange; int Result = std::max(0,Index); - if (Result >= mLines->count()) + if (Result >= mDocument->count()) return Result; if (Result == 0) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(Result-1)); + mHighlighter->setState(mDocument->ranges(Result-1)); } do { - mHighlighter->setLine(mLines->getString(Result), Result); + mHighlighter->setLine(mDocument->getString(Result), Result); mHighlighter->nextToEol(); iRange = mHighlighter->getRangeState(); if (Result > canStopIndex){ - if (mLines->ranges(Result).state == iRange.state - && mLines->ranges(Result).braceLevel == iRange.braceLevel - && mLines->ranges(Result).parenthesisLevel == iRange.parenthesisLevel - && mLines->ranges(Result).bracketLevel == iRange.bracketLevel + if (mDocument->ranges(Result).state == iRange.state + && mDocument->ranges(Result).braceLevel == iRange.braceLevel + && mDocument->ranges(Result).parenthesisLevel == iRange.parenthesisLevel + && mDocument->ranges(Result).bracketLevel == iRange.bracketLevel ) { if (mUseCodeFolding) rescanFolds(); return Result;// avoid the final Decrement } } - mLines->setRange(Result,iRange); + mDocument->setRange(Result,iRange); Result ++ ; - } while (Result < mLines->count()); + } while (Result < mDocument->count()); Result--; if (mUseCodeFolding) rescanFolds(); @@ -3400,28 +3385,28 @@ void SynEdit::rescanRange(int line) return; line--; line = std::max(0,line); - if (line >= mLines->count()) + if (line >= mDocument->count()) return; if (line == 0) { mHighlighter->resetState(); } else { - mHighlighter->setState(mLines->ranges(line-1)); + mHighlighter->setState(mDocument->ranges(line-1)); } - mHighlighter->setLine(mLines->getString(line), line); + mHighlighter->setLine(mDocument->getString(line), line); mHighlighter->nextToEol(); SynRangeState iRange = mHighlighter->getRangeState(); - mLines->setRange(line,iRange); + mDocument->setRange(line,iRange); } void SynEdit::rescanRanges() { - if (mHighlighter && !mLines->empty()) { + if (mHighlighter && !mDocument->empty()) { mHighlighter->resetState(); - for (int i =0;icount();i++) { - mHighlighter->setLine(mLines->getString(i), i); + for (int i =0;icount();i++) { + mHighlighter->setLine(mDocument->getString(i), i); mHighlighter->nextToEol(); - mLines->setRange(i, mHighlighter->getRangeState()); + mDocument->setRange(i, mHighlighter->getRangeState()); } } if (mUseCodeFolding) @@ -3448,7 +3433,7 @@ void SynEdit::collapse(PSynEditFoldRange FoldRange) // Extract caret from fold if ((mCaretY > FoldRange->fromLine) && (mCaretY <= FoldRange->toLine)) { - setCaretXY(BufferCoord{mLines->getString(FoldRange->fromLine - 1).length() + 1, + setCaretXY(BufferCoord{mDocument->getString(FoldRange->fromLine - 1).length() + 1, FoldRange->fromLine}); } @@ -3557,7 +3542,7 @@ void SynEdit::scanForFoldRanges(PSynEditFoldRanges TopFoldRanges) //this func should only be used in findSubFoldRange int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName) { - QString CurLine = mLines->getString(Line); + QString CurLine = mDocument->getString(Line); if (!mHighlighter){ for (int i=startChar; iopenSymbol == "{" && mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}"); - while (Line < mLines->count()) { // index is valid for LinesToScan and fLines + while (Line < mDocument->count()) { // index is valid for LinesToScan and fLines // If there is a collapsed fold over here, skip it CollapsedFold = collapsedFoldStartAtLine(Line + 1); // only collapsed folds remain if (CollapsedFold) { @@ -3606,9 +3591,9 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P //we just use braceLevel if (useBraces) { // Find an opening character on this line - CurLine = mLines->getString(Line); - if (mLines->rightBraces(Line)>0) { - for (int i=0; irightBraces(Line);i++) { + CurLine = mDocument->getString(Line); + if (mDocument->rightBraces(Line)>0) { + for (int i=0; irightBraces(Line);i++) { // Stop the recursion if we find a closing char, and return to our parent if (Parent) { Parent->toLine = Line + 1; @@ -3621,8 +3606,8 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P } } } - if (mLines->leftBraces(Line)>0) { - for (int i=0; ileftBraces(Line);i++) { + if (mDocument->leftBraces(Line)>0) { + for (int i=0; ileftBraces(Line);i++) { // Add it to the top list of folds Parent = parentFoldRanges->addByParts( Parent, @@ -3636,9 +3621,9 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P } else { // Find an opening character on this line - CurLine = mLines->getString(Line); + CurLine = mDocument->getString(Line); - mHighlighter->setState(mLines->ranges(Line)); + mHighlighter->setState(mDocument->ranges(Line)); mHighlighter->setLine(CurLine,Line); QString token; @@ -3737,7 +3722,7 @@ QString SynEdit::substringByColumns(const QString &s, int startColumn, int &colL if (i>=len) break; if (s[i] == '\t') - columns += mTabWidth - (columns % mTabWidth); + columns += tabWidth() - (columns % tabWidth()); else columns += charColumns(s[i]); i++; @@ -3758,7 +3743,7 @@ QString SynEdit::substringByColumns(const QString &s, int startColumn, int &colL while (iresetColumns(); + if (newTabWidth!=tabWidth()) { + mDocument->setTabWidth(newTabWidth); invalidate(); } } @@ -4364,9 +4343,9 @@ void SynEdit::doUndoItem() } if ( (Item->changeReason() == SynChangeReason::crDeleteAfterCursor || Item->changeReason() == SynChangeReason::crSilentDeleteAfterCursor) - && (TmpPos.Line > mLines->count())) { - internalSetCaretXY(BufferCoord{1, mLines->count()}); - mLines->add(""); + && (TmpPos.Line > mDocument->count())) { + internalSetCaretXY(BufferCoord{1, mDocument->count()}); + mDocument->add(""); } setCaretXY(TmpPos); setSelTextPrimitiveEx( @@ -4401,11 +4380,11 @@ void SynEdit::doUndoItem() // the Caret's position manualy. internalSetCaretXY(Item->changeStartPos()); if (mCaretY > 0) { - QString TmpStr = mLines->getString(mCaretY - 1); + QString TmpStr = mDocument->getString(mCaretY - 1); if ( (mCaretX > TmpStr.length() + 1) && (leftSpaces(Item->changeStr()) == 0)) TmpStr = TmpStr + QString(mCaretX - 1 - TmpStr.length(), ' '); properSetLine(mCaretY - 1, TmpStr + Item->changeStr()); - mLines->deleteAt(mCaretY); + mDocument->deleteAt(mCaretY); doLinesDeleted(mCaretY, 1); } mRedoList->AddChange( @@ -4660,20 +4639,20 @@ void SynEdit::doRedoItem() e = Item->changeEndPos().Line - 1; QString TempString; for (int i = Item->changeStartPos().Line; i<= e;i++) { - QString line = mLines->getString(i - 1); + QString line = mDocument->getString(i - 1); if (line.isEmpty()) continue; if (line[0]!=' ' && line[0]!='\t') continue; int charsToDelete = 0; - while (charsToDelete < mTabWidth && + while (charsToDelete < tabWidth() && charsToDelete < line.length() && line[charsToDelete] == ' ') charsToDelete++; if (charsToDelete == 0) charsToDelete = 1; QString tempString = line.mid(charsToDelete); - mLines->putString(i-1,tempString); + mDocument->putString(i-1,tempString); } mUndoList->AddChange(Item->changeReason(), Item->changeStartPos(), Item->changeEndPos(), Item->changeStr(), Item->changeSelMode()); @@ -4731,15 +4710,15 @@ QString SynEdit::selText() switch(mActiveSelectionMode) { case SynSelectionMode::smNormal: if (First == Last) - return mLines->getString(First).mid(ColFrom-1, ColTo - ColFrom); + return mDocument->getString(First).mid(ColFrom-1, ColTo - ColFrom); else { - QString result = mLines->getString(First).mid(ColFrom-1); + QString result = mDocument->getString(First).mid(ColFrom-1); result+= lineBreak(); for (int i = First + 1; i<=Last - 1; i++) { - result += mLines->getString(i); + result += mDocument->getString(i); result+=lineBreak(); } - result += mLines->getString(Last).leftRef(ColTo-1); + result += mDocument->getString(Last).leftRef(ColTo-1); return result; } case SynSelectionMode::smColumn: @@ -4754,7 +4733,7 @@ QString SynEdit::selText() for (int i = First; i <= Last; i++) { int l = columnToChar(i+1,ColFrom); int r = columnToChar(i+1,ColTo-1)+1; - QString s = mLines->getString(i); + QString s = mDocument->getString(i); result += s.mid(l-1,r-l); if (igetString(i); + result += mDocument->getString(i); result+=lineBreak(); } - result += mLines->getString(Last); - if (Last < mLines->count() - 1) + result += mDocument->getString(Last); + if (Last < mDocument->count() - 1) result+=lineBreak(); return result; } @@ -4782,7 +4761,7 @@ QString SynEdit::selText() QString SynEdit::lineBreak() { - return mLines->lineBreak(); + return mDocument->lineBreak(); } bool SynEdit::useCodeFolding() const @@ -4804,16 +4783,16 @@ SynEditCodeFolding &SynEdit::codeFolding() QString SynEdit::lineText() const { - if (mCaretY >= 1 && mCaretY <= mLines->count()) - return mLines->getString(mCaretY - 1); + if (mCaretY >= 1 && mCaretY <= mDocument->count()) + return mDocument->getString(mCaretY - 1); else return QString(); } void SynEdit::setLineText(const QString s) { - if (mCaretY >= 1 && mCaretY <= mLines->count()) - mLines->putString(mCaretY-1,s); + if (mCaretY >= 1 && mCaretY <= mDocument->count()) + mDocument->putString(mCaretY-1,s); } PSynHighlighter SynEdit::highlighter() const @@ -4829,9 +4808,9 @@ void SynEdit::setHighlighter(const PSynHighlighter &highlighter) oldHighlighter->language() == highlighter->language()) { } else { recalcCharExtent(); - mLines->beginUpdate(); + mDocument->beginUpdate(); auto action=finally([this]{ - mLines->endUpdate(); + mDocument->endUpdate(); }); rescanRanges(); } @@ -4839,14 +4818,14 @@ void SynEdit::setHighlighter(const PSynHighlighter &highlighter) invalidate(); } -const PSynEditStringList& SynEdit::lines() const +const PSynDocument& SynEdit::document() const { - return mLines; + return mDocument; } bool SynEdit::empty() { - return mLines->empty(); + return mDocument->empty(); } void SynEdit::commandProcessor(SynEditorCommand Command, QChar AChar, void *pData) @@ -4870,8 +4849,8 @@ void SynEdit::moveCaretHorz(int DX, bool isSelection) if (bChangeY && (DX == -1) && (ptO.Char == 1) && (ptO.Line > 1)) { // end of previous line ptDst.Line--; - ptDst.Char = mLines->getString(ptDst.Line - 1).length() + 1; - } else if (bChangeY && (DX == 1) && (ptO.Char > nLineLen) && (ptO.Line < mLines->count())) { + ptDst.Char = mDocument->getString(ptDst.Line - 1).length() + 1; + } else if (bChangeY && (DX == 1) && (ptO.Char > nLineLen) && (ptO.Line < mDocument->count())) { // start of next line ptDst.Line++; ptDst.Char=1; @@ -4901,7 +4880,7 @@ void SynEdit::moveCaretVert(int DY, bool isSelection) ptDst.Row+=DY; if (DY >= 0) { - if (rowToLine(ptDst.Row) > mLines->count()) + if (rowToLine(ptDst.Row) > mDocument->count()) ptDst.Row = std::max(1, displayLineCount()); } else { if (ptDst.Row < 1) @@ -4955,7 +4934,7 @@ void SynEdit::moveCaretToLineStart(bool isSelection) int newX; // home key enhancement if (mOptions.testFlag(SynEditorOption::eoEnhanceHomeKey)) { - QString s = mLines->getString(mCaretY - 1); + QString s = mDocument->getString(mCaretY - 1); int first_nonblank = 0; int vMaxX = s.length(); @@ -5019,9 +4998,9 @@ void SynEdit::setSelTextPrimitive(const QString &aValue) void SynEdit::setSelTextPrimitiveEx(SynSelectionMode PasteMode, const QString &Value, bool AddToUndoList) { incPaintLock(); - mLines->beginUpdate(); + mDocument->beginUpdate(); auto action = finally([this] { - mLines->endUpdate(); + mDocument->endUpdate(); decPaintLock(); }); BufferCoord BB = blockBegin(); @@ -5092,7 +5071,7 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS // search the whole line in the line selection mode if (mActiveSelectionMode == SynSelectionMode::smLine) { ptStart.Char = 1; - ptEnd.Char = mLines->getString(ptEnd.Line - 1).length(); + ptEnd.Char = mDocument->getString(ptEnd.Line - 1).length(); } else if (mActiveSelectionMode == SynSelectionMode::smColumn) { // make sure the start column is smaller than the end column if (ptStart.Char > ptEnd.Char) @@ -5107,8 +5086,8 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS } else { ptStart.Char = 1; ptStart.Line = 1; - ptEnd.Line = mLines->count(); - ptEnd.Char = mLines->getString(ptEnd.Line - 1).length(); + ptEnd.Line = mDocument->count(); + ptEnd.Char = mDocument->getString(ptEnd.Line - 1).length(); if (bFromCursor) { if (bBackward) ptEnd = caretXY(); @@ -5139,7 +5118,7 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS // 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(mLines->getString(ptCurrent.Line - 1)); + int nInLine = searchEngine->findAll(mDocument->getString(ptCurrent.Line - 1)); int iResultOffset = 0; if (bBackward) i = searchEngine->resultCount()-1; @@ -5237,8 +5216,8 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS bFromCursor = false; ptStart.Char = 1; ptStart.Line = 1; - ptEnd.Line = mLines->count(); - ptEnd.Char = mLines->getString(ptEnd.Line - 1).length(); + ptEnd.Line = mDocument->count(); + ptEnd.Char = mDocument->getString(ptEnd.Line - 1).length(); if (bBackward) { ptStart = originCaretXY; ptCurrent = ptEnd; @@ -5287,9 +5266,9 @@ void SynEdit::doLinesInserted(int firstLine, int count) void SynEdit::properSetLine(int ALine, const QString &ALineText, bool notify) { if (mOptions.testFlag(eoTrimTrailingSpaces)) { - mLines->putString(ALine,trimRight(ALineText),notify); + mDocument->putString(ALine,trimRight(ALineText),notify); } else { - mLines->putString(ALine,ALineText,notify); + mDocument->putString(ALine,ALineText,notify); } } @@ -5299,14 +5278,14 @@ void SynEdit::deleteSelection(const BufferCoord &BB, const BufferCoord &BE) int MarkOffset = 0; switch(mActiveSelectionMode) { case SynSelectionMode::smNormal: - if (mLines->count() > 0) { + 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 = mLines->getString(BB.Line - 1).mid(0, BB.Char - 1) - + mLines->getString(BE.Line - 1).mid(BE.Char-1); + QString TempString = mDocument->getString(BB.Line - 1).mid(0, BB.Char - 1) + + mDocument->getString(BE.Line - 1).mid(BE.Char-1); // Delete all lines in the selection range. - mLines->deleteLines(BB.Line, BE.Line - BB.Line); + mDocument->deleteLines(BB.Line, BE.Line - BB.Line); properSetLine(BB.Line-1,TempString); UpdateMarks = true; internalSetCaretXY(BB); @@ -5324,7 +5303,7 @@ void SynEdit::deleteSelection(const BufferCoord &BB, const BufferCoord &BE) for (int i = First; i <= Last; i++) { int l = columnToChar(i+1,ColFrom); int r = columnToChar(i+1,ColTo-1)+1; - QString s = mLines->getString(i); + QString s = mDocument->getString(i); s.remove(l-1,r-l); properSetLine(i,s); } @@ -5335,11 +5314,11 @@ void SynEdit::deleteSelection(const BufferCoord &BB, const BufferCoord &BE) break; } case SynSelectionMode::smLine: - if (BE.Line == mLines->count()) { - mLines->putString(BE.Line - 1,""); - mLines->deleteLines(BB.Line-1,BE.Line-BB.Line); + if (BE.Line == mDocument->count()) { + mDocument->putString(BE.Line - 1,""); + mDocument->deleteLines(BB.Line-1,BE.Line-BB.Line); } else { - mLines->deleteLines(BB.Line-1,BE.Line-BB.Line+1); + mDocument->deleteLines(BB.Line-1,BE.Line-BB.Line+1); } // smLine deletion always resets to first column. internalSetCaretXY(BufferCoord{1, BB.Line}); @@ -5384,9 +5363,9 @@ void SynEdit::insertText(const QString &Value, SynSelectionMode PasteMode,bool A int SynEdit::insertTextByNormalMode(const QString &Value) { - mLines->beginUpdate(); + mDocument->beginUpdate(); auto actionLines = finally([this] { - mLines->endUpdate(); + mDocument->endUpdate(); }); QString sLeftSide; QString sRightSide; @@ -5424,7 +5403,7 @@ int SynEdit::insertTextByNormalMode(const QString &Value) } else Str = sLeftSide + Value.mid(0, P - Start); properSetLine(caretY - 1, Str); - mLines->insertLines(caretY, CountLines(Value,P)); + mDocument->insertLines(caretY, CountLines(Value,P)); } else { Str = sLeftSide + Value + sRightSide; properSetLine(caretY - 1, Str); @@ -5504,20 +5483,20 @@ int SynEdit::insertTextByColumnMode(const QString &value, bool addToUndoList) if (p != start) { str = value.mid(start,p-start); // Move(Start^, Str[1], P - Start); - if (mCaretY > mLines->count()) { + if (mCaretY > mDocument->count()) { result++; tempString = QString(insertCol - 1,' ') + str; - mLines->add(""); + mDocument->add(""); if (addToUndoList) { lineBreakPos.Line = mCaretY - 1; - lineBreakPos.Char = mLines->getString(mCaretY - 2).length() + 1; + lineBreakPos.Char = mDocument->getString(mCaretY - 2).length() + 1; mUndoList->AddChange(SynChangeReason::crLineBreak, lineBreakPos, lineBreakPos, "", SynSelectionMode::smNormal); } } else { - tempString = mLines->getString(mCaretY - 1); + tempString = mDocument->getString(mCaretY - 1); len = stringColumns(tempString,0); if (len < insertCol) { tempString = tempString + QString(insertCol - len - 1,' ') + str; @@ -5573,8 +5552,8 @@ int SynEdit::insertTextByLineMode(const QString &Value) Str = Value.mid(Start,P - Start); else Str = ""; - if ((mCaretY == mLines->count()) || mInserting) { - mLines->insert(mCaretY - 1, ""); + if ((mCaretY == mDocument->count()) || mInserting) { + mDocument->insert(mCaretY - 1, ""); Result++; } properSetLine(mCaretY - 1, Str); @@ -5731,8 +5710,8 @@ void SynEdit::ExecuteCommand(SynEditorCommand Command, QChar AChar, void *pData) break; case SynEditorCommand::ecEditorEnd: case SynEditorCommand::ecSelEditorEnd: - if (!mLines->empty()) { - moveCaretVert(mLines->count()-mCaretY, Command == SynEditorCommand::ecSelEditorEnd); + if (!mDocument->empty()) { + moveCaretVert(mDocument->count()-mCaretY, Command == SynEditorCommand::ecSelEditorEnd); moveCaretToLineEnd(Command == SynEditorCommand::ecSelEditorEnd); } break; @@ -6097,6 +6076,8 @@ bool SynEdit::event(QEvent *event) break; case QEvent::FontChange: synFontChanged(); + if (mDocument) + mDocument->setFontMetrics(font()); break; case QEvent::MouseMove: { updateMouseCursor(); @@ -6531,7 +6512,7 @@ void SynEdit::onLinesChanged() invalidateRect(mInvalidateRect); mInvalidateRect = {0,0,0,0}; if (mGutter.showLineNumbers() && (mGutter.autoSize())) - mGutter.autoSizeDigitCount(mLines->count()); + mGutter.autoSizeDigitCount(mDocument->count()); //if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof)) setTopLine(mTopLine); } @@ -6561,7 +6542,7 @@ void SynEdit::onLinesDeleted(int index, int count) { if (mUseCodeFolding) foldOnListDeleted(index + 1, count); - if (mHighlighter && mLines->count() > 0) + if (mHighlighter && mDocument->count() > 0) scanFrom(index, index+1); invalidateLines(index + 1, INT_MAX); invalidateGutterLines(index + 1, INT_MAX); @@ -6571,7 +6552,7 @@ void SynEdit::onLinesInserted(int index, int count) { if (mUseCodeFolding) foldOnListInserted(index + 1, count); - if (mHighlighter && mLines->count() > 0) { + if (mHighlighter && mDocument->count() > 0) { // int vLastScan = index; // do { scanFrom(index, index+count); @@ -6589,7 +6570,7 @@ void SynEdit::onLinesPutted(int index, int count) vEndLine = std::max(vEndLine, scanFrom(index, index+count) + 1); // If this editor is chained then the real owner of text buffer will probably // have already parsed the changes, so ScanFrom will return immediately. - if (mLines != mOrigLines) + if (mDocument != mOrigLines) vEndLine = INT_MAX; } invalidateLines(index + 1, vEndLine); @@ -6638,11 +6619,11 @@ BufferCoord SynEdit::blockEnd() const void SynEdit::setBlockEnd(BufferCoord Value) { //setActiveSelectionMode(mSelectionMode); - Value.Line = minMax(Value.Line, 1, mLines->count()); - Value.Char = minMax(Value.Char, 1, mLines->lengthOfLongestLine()+1); + Value.Line = minMax(Value.Line, 1, mDocument->count()); + Value.Char = minMax(Value.Char, 1, mDocument->lengthOfLongestLine()+1); if (mActiveSelectionMode == SynSelectionMode::smNormal) { - if (Value.Line >= 1 && Value.Line <= mLines->count()) - Value.Char = std::min(Value.Char, mLines->getString(Value.Line - 1).length() + 1); + if (Value.Line >= 1 && Value.Line <= mDocument->count()) + Value.Char = std::min(Value.Char, mDocument->getString(Value.Line - 1).length() + 1); else Value.Char = 1; } @@ -6664,7 +6645,7 @@ void SynEdit::setBlockEnd(BufferCoord Value) void SynEdit::setSelLength(int Value) { - if (mBlockBegin.Line>mLines->count() || mBlockBegin.Line<=0) + if (mBlockBegin.Line>mDocument->count() || mBlockBegin.Line<=0) return; if (Value >= 0) { @@ -6672,8 +6653,8 @@ void SynEdit::setSelLength(int Value) int ch = mBlockBegin.Char; int x = ch + Value; QString line; - while (y<=mLines->count()) { - line = mLines->getString(y-1); + while (y<=mDocument->count()) { + line = mDocument->getString(y-1); if (x <= line.length()+2) { if (x==line.length()+2) x = line.length()+1; @@ -6682,9 +6663,9 @@ void SynEdit::setSelLength(int Value) x -= line.length()+2; y ++; } - if (y>mLines->count()) { - y = mLines->count(); - x = mLines->getString(y-1).length()+1; + if (y>mDocument->count()) { + y = mDocument->count(); + x = mDocument->getString(y-1).length()+1; } BufferCoord iNewEnd{x,y}; setCaretAndSelection(iNewEnd, mBlockBegin, iNewEnd); @@ -6700,12 +6681,12 @@ void SynEdit::setSelLength(int Value) break; } y--; - line = mLines->getString(y-1); + line = mDocument->getString(y-1); x += line.length()+2; } - if (y>mLines->count()) { - y = mLines->count(); - x = mLines->getString(y-1).length()+1; + if (y>mDocument->count()) { + y = mDocument->count(); + x = mDocument->getString(y-1).length()+1; } BufferCoord iNewStart{x,y}; setCaretAndSelection(iNewStart, iNewStart, mBlockBegin); @@ -6731,11 +6712,11 @@ void SynEdit::setBlockBegin(BufferCoord value) int nInval1, nInval2; bool SelChanged; //setActiveSelectionMode(mSelectionMode); - value.Char = minMax(value.Char, 1, mLines->lengthOfLongestLine()+1); - value.Line = minMax(value.Line, 1, mLines->count()); + value.Char = minMax(value.Char, 1, mDocument->lengthOfLongestLine()+1); + value.Line = minMax(value.Line, 1, mDocument->count()); if (mActiveSelectionMode == SynSelectionMode::smNormal) { - if (value.Line >= 1 && value.Line <= mLines->count()) - value.Char = std::min(value.Char, mLines->getString(value.Line - 1).length() + 1); + if (value.Line >= 1 && value.Line <= mDocument->count()) + value.Char = std::min(value.Char, mDocument->getString(value.Line - 1).length() + 1); else value.Char = 1; } @@ -6813,7 +6794,7 @@ void SynEdit::onRedoAdded() void SynEdit::onGutterChanged() { if (mGutter.showLineNumbers() && mGutter.autoSize()) - mGutter.autoSizeDigitCount(mLines->count()); + mGutter.autoSizeDigitCount(mDocument->count()); int nW; if (mGutter.useFontStyle()) { QFontMetrics fm=QFontMetrics(mGutter.font()); diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 3bd36fe9..b633a5a9 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -348,7 +348,7 @@ public: QString lineText() const; void setLineText(const QString s); - const PSynEditStringList& lines() const; + const PSynDocument& document() const; bool empty(); SynSelectionMode selectionMode() const; @@ -361,7 +361,7 @@ public: SynEditorOptions getOptions() const; void setOptions(const SynEditorOptions &Value); - int tabWidth() const; + int tabWidth() const { return mDocument->tabWidth(); } void setTabWidth(int tabWidth); QColor caretColor() const; @@ -642,8 +642,8 @@ private: bool mInserting; bool mPainting; - PSynEditStringList mLines; - PSynEditStringList mOrigLines; + PSynDocument mDocument; + PSynDocument mOrigLines; PSynEditUndoList mOrigUndoList; PSynEditUndoList mOrigRedoList; int mLinesInWindow; @@ -690,7 +690,6 @@ private: bool mWantReturns; bool mWantTabs; SynGutter mGutter; - int mTabWidth; QRect mInvalidateRect; SynStateFlags mStateFlags; SynEditorOptions mOptions; @@ -748,41 +747,41 @@ friend class SynEditTextPainter; // QWidget interface protected: -void paintEvent(QPaintEvent *event) override; -void resizeEvent(QResizeEvent *event) override; -void timerEvent(QTimerEvent *event) override; -bool event(QEvent *event) override; -void focusInEvent(QFocusEvent *event) override; -void focusOutEvent(QFocusEvent *event) override; -void keyPressEvent(QKeyEvent *event) override; -void mousePressEvent(QMouseEvent *event) override; -void mouseReleaseEvent(QMouseEvent *event) override; -void mouseMoveEvent(QMouseEvent *event) override; -void mouseDoubleClickEvent(QMouseEvent *event) override; -void inputMethodEvent(QInputMethodEvent *event) override; -void leaveEvent(QEvent *event) override; -void wheelEvent(QWheelEvent *event) override; + void paintEvent(QPaintEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + void timerEvent(QTimerEvent *event) override; + bool event(QEvent *event) override; + void focusInEvent(QFocusEvent *event) override; + void focusOutEvent(QFocusEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseDoubleClickEvent(QMouseEvent *event) override; + void inputMethodEvent(QInputMethodEvent *event) override; + void leaveEvent(QEvent *event) override; + void wheelEvent(QWheelEvent *event) override; // QAbstractScrollArea interface protected: -bool viewportEvent(QEvent * event) override; + bool viewportEvent(QEvent * event) override; -// QWidget interface -public: -QVariant inputMethodQuery(Qt::InputMethodQuery property) const override; + // QWidget interface + public: + QVariant inputMethodQuery(Qt::InputMethodQuery property) const override; -// QWidget interface -const QFont &fontForNonAscii() const; -void setFontForNonAscii(const QFont &newFontForNonAscii); + // QWidget interface + const QFont &fontForNonAscii() const; + void setFontForNonAscii(const QFont &newFontForNonAscii); -int mouseSelectionScrollSpeed() const; -void setMouseSelectionScrollSpeed(int newMouseSelectionScrollSpeed); + int mouseSelectionScrollSpeed() const; + void setMouseSelectionScrollSpeed(int newMouseSelectionScrollSpeed); protected: -void dragEnterEvent(QDragEnterEvent *event) override; -void dropEvent(QDropEvent *event) override; -void dragMoveEvent(QDragMoveEvent *event) override; -void dragLeaveEvent(QDragLeaveEvent *event) override; + void dragEnterEvent(QDragEnterEvent *event) override; + void dropEvent(QDropEvent *event) override; + void dragMoveEvent(QDragMoveEvent *event) override; + void dragLeaveEvent(QDragLeaveEvent *event) override; }; #endif // SYNEDIT_H diff --git a/RedPandaIDE/qsynedit/TextBuffer.cpp b/RedPandaIDE/qsynedit/TextBuffer.cpp index 2090918a..9604fcbf 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.cpp +++ b/RedPandaIDE/qsynedit/TextBuffer.cpp @@ -25,16 +25,20 @@ #include "../utils.h" #include "../platform.h" #include +#include -SynEditStringList::SynEditStringList(SynEdit *pEdit, QObject *parent): +SynDocument::SynDocument(const QFont& font, QObject *parent): QObject(parent), - mEdit(pEdit), + mTabWidth(4), + mFontMetrics(font), mMutex(QMutex::Recursive) { + mAppendNewLineAtEOF = true; mFileEndingType = FileEndingType::Windows; mIndexOfLongestLine = -1; mUpdateCount = 0; + mCharWidth = mFontMetrics.horizontalAdvance("M"); } static void ListIndexOutOfBounds(int index) { @@ -43,29 +47,29 @@ static void ListIndexOutOfBounds(int index) { -int SynEditStringList::parenthesisLevels(int Index) +int SynDocument::parenthesisLevels(int Index) { QMutexLocker locker(&mMutex); - if (Index>=0 && Index < mList.size()) { - return mList[Index]->fRange.parenthesisLevel; + if (Index>=0 && Index < mLines.size()) { + return mLines[Index]->fRange.parenthesisLevel; } else return 0; } -int SynEditStringList::bracketLevels(int Index) +int SynDocument::bracketLevels(int Index) { QMutexLocker locker(&mMutex); - if (Index>=0 && Index < mList.size()) { - return mList[Index]->fRange.bracketLevel; + if (Index>=0 && Index < mLines.size()) { + return mLines[Index]->fRange.bracketLevel; } else return 0; } -int SynEditStringList::braceLevels(int Index) +int SynDocument::braceLevels(int Index) { QMutexLocker locker(&mMutex); - if (Index>=0 && Index < mList.size()) { - return mList[Index]->fRange.braceLevel; + if (Index>=0 && Index < mLines.size()) { + return mLines[Index]->fRange.braceLevel; } else return 0; } @@ -81,43 +85,43 @@ int SynEditStringList::braceLevels(int Index) // return QString(); //} -int SynEditStringList::lineColumns(int Index) +int SynDocument::lineColumns(int Index) { QMutexLocker locker(&mMutex); - if (Index>=0 && Index < mList.size()) { - if (mList[Index]->fColumns == -1) { + if (Index>=0 && Index < mLines.size()) { + if (mLines[Index]->fColumns == -1) { return calculateLineColumns(Index); } else - return mList[Index]->fColumns; + return mLines[Index]->fColumns; } else return 0; } -int SynEditStringList::leftBraces(int Index) +int SynDocument::leftBraces(int Index) { QMutexLocker locker(&mMutex); - if (Index>=0 && Index < mList.size()) { - return mList[Index]->fRange.leftBraces; + if (Index>=0 && Index < mLines.size()) { + return mLines[Index]->fRange.leftBraces; } else return 0; } -int SynEditStringList::rightBraces(int Index) +int SynDocument::rightBraces(int Index) { QMutexLocker locker(&mMutex); - if (Index>=0 && Index < mList.size()) { - return mList[Index]->fRange.rightBraces; + if (Index>=0 && Index < mLines.size()) { + return mLines[Index]->fRange.rightBraces; } else return 0; } -int SynEditStringList::lengthOfLongestLine() { +int SynDocument::lengthOfLongestLine() { QMutexLocker locker(&mMutex); if (mIndexOfLongestLine < 0) { int MaxLen = -1; mIndexOfLongestLine = -1; - if (mList.count() > 0 ) { - for (int i=0;i 0 ) { + for (int i=0;i MaxLen) { MaxLen = len; @@ -127,12 +131,12 @@ int SynEditStringList::lengthOfLongestLine() { } } if (mIndexOfLongestLine >= 0) - return mList[mIndexOfLongestLine]->fColumns; + return mLines[mIndexOfLongestLine]->fColumns; else return 0; } -QString SynEditStringList::lineBreak() const +QString SynDocument::lineBreak() const { switch(mFileEndingType) { case FileEndingType::Linux: @@ -145,97 +149,97 @@ QString SynEditStringList::lineBreak() const return "\n"; } -SynRangeState SynEditStringList::ranges(int Index) +SynRangeState SynDocument::ranges(int Index) { QMutexLocker locker(&mMutex); - if (Index>=0 && Index < mList.size()) { - return mList[Index]->fRange; + if (Index>=0 && Index < mLines.size()) { + return mLines[Index]->fRange; } else { ListIndexOutOfBounds(Index); } return {0}; } -void SynEditStringList::insertItem(int Index, const QString &s) +void SynDocument::insertItem(int Index, const QString &s) { beginUpdate(); - PSynEditStringRec line = std::make_shared(); + PSynDocumentLine line = std::make_shared(); line->fString = s; mIndexOfLongestLine = -1; - mList.insert(Index,line); + mLines.insert(Index,line); endUpdate(); } -void SynEditStringList::addItem(const QString &s) +void SynDocument::addItem(const QString &s) { beginUpdate(); - PSynEditStringRec line = std::make_shared(); + PSynDocumentLine line = std::make_shared(); line->fString = s; mIndexOfLongestLine = -1; - mList.append(line); + mLines.append(line); endUpdate(); } -bool SynEditStringList::getAppendNewLineAtEOF() +bool SynDocument::getAppendNewLineAtEOF() { QMutexLocker locker(&mMutex); return mAppendNewLineAtEOF; } -void SynEditStringList::setAppendNewLineAtEOF(bool appendNewLineAtEOF) +void SynDocument::setAppendNewLineAtEOF(bool appendNewLineAtEOF) { QMutexLocker locker(&mMutex); mAppendNewLineAtEOF = appendNewLineAtEOF; } -void SynEditStringList::setRange(int Index, const SynRangeState& ARange) +void SynDocument::setRange(int Index, const SynRangeState& ARange) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>=mList.count()) { + if (Index<0 || Index>=mLines.count()) { ListIndexOutOfBounds(Index); } beginUpdate(); - mList[Index]->fRange = ARange; + mLines[Index]->fRange = ARange; endUpdate(); } -QString SynEditStringList::getString(int Index) +QString SynDocument::getString(int Index) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>=mList.count()) { + if (Index<0 || Index>=mLines.count()) { return QString(); } - return mList[Index]->fString; + return mLines[Index]->fString; } -int SynEditStringList::count() +int SynDocument::count() { QMutexLocker locker(&mMutex); - return mList.count(); + return mLines.count(); } -void *SynEditStringList::getObject(int Index) +void *SynDocument::getObject(int Index) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>=mList.count()) { + if (Index<0 || Index>=mLines.count()) { return nullptr; } - return mList[Index]->fObject; + return mLines[Index]->fObject; } -QString SynEditStringList::text() +QString SynDocument::text() { QMutexLocker locker(&mMutex); return getTextStr(); } -void SynEditStringList::setText(const QString &text) +void SynDocument::setText(const QString &text) { QMutexLocker locker(&mMutex); putTextStr(text); } -void SynEditStringList::setContents(const QStringList &text) +void SynDocument::setContents(const QStringList &text) { QMutexLocker locker(&mMutex); beginUpdate(); @@ -245,7 +249,7 @@ void SynEditStringList::setContents(const QStringList &text) internalClear(); if (text.count() > 0) { mIndexOfLongestLine = -1; - int FirstAdded = mList.count(); + int FirstAdded = mLines.count(); foreach (const QString& s,text) { addItem(s); @@ -254,18 +258,18 @@ void SynEditStringList::setContents(const QStringList &text) } } -QStringList SynEditStringList::contents() +QStringList SynDocument::contents() { QMutexLocker locker(&mMutex); QStringList Result; - SynEditStringRecList list = mList; - foreach (const PSynEditStringRec& line, list) { + SynDocumentLines list = mLines; + foreach (const PSynDocumentLine& line, list) { Result.append(line->fString); } return Result; } -void SynEditStringList::beginUpdate() +void SynDocument::beginUpdate() { if (mUpdateCount == 0) { setUpdateState(true); @@ -273,7 +277,7 @@ void SynEditStringList::beginUpdate() mUpdateCount++; } -void SynEditStringList::endUpdate() +void SynDocument::endUpdate() { mUpdateCount--; if (mUpdateCount == 0) { @@ -282,18 +286,18 @@ void SynEditStringList::endUpdate() } -int SynEditStringList::add(const QString &s) +int SynDocument::add(const QString &s) { QMutexLocker locker(&mMutex); beginUpdate(); - int Result = mList.count(); + int Result = mLines.count(); insertItem(Result, s); emit inserted(Result,1); endUpdate(); return Result; } -void SynEditStringList::addStrings(const QStringList &Strings) +void SynDocument::addStrings(const QStringList &Strings) { QMutexLocker locker(&mMutex); if (Strings.count() > 0) { @@ -302,7 +306,7 @@ void SynEditStringList::addStrings(const QStringList &Strings) auto action = finally([this]{ endUpdate(); }); - int FirstAdded = mList.count(); + int FirstAdded = mLines.count(); for (const QString& s:Strings) { addItem(s); @@ -311,11 +315,11 @@ void SynEditStringList::addStrings(const QStringList &Strings) } } -int SynEditStringList::getTextLength() +int SynDocument::getTextLength() { QMutexLocker locker(&mMutex); int Result = 0; - foreach (const PSynEditStringRec& line, mList ) { + foreach (const PSynDocumentLine& line, mLines ) { Result += line->fString.length(); if (mFileEndingType == FileEndingType::Windows) { Result += 2; @@ -326,18 +330,18 @@ int SynEditStringList::getTextLength() return Result; } -void SynEditStringList::clear() +void SynDocument::clear() { QMutexLocker locker(&mMutex); internalClear(); } -void SynEditStringList::deleteLines(int Index, int NumLines) +void SynDocument::deleteLines(int Index, int NumLines) { QMutexLocker locker(&mMutex); if (NumLines<=0) return; - if ((Index < 0) || (Index >= mList.count())) { + if ((Index < 0) || (Index >= mLines.count())) { ListIndexOutOfBounds(Index); } beginUpdate(); @@ -347,27 +351,27 @@ void SynEditStringList::deleteLines(int Index, int NumLines) if (mIndexOfLongestLine>=Index && (mIndexOfLongestLine = mList.count())) { + if ((Index1 < 0) || (Index1 >= mLines.count())) { ListIndexOutOfBounds(Index1); } - if ((Index2 < 0) || (Index2 >= mList.count())) { + if ((Index2 < 0) || (Index2 >= mLines.count())) { ListIndexOutOfBounds(Index2); } beginUpdate(); - PSynEditStringRec temp = mList[Index1]; - mList[Index1]=mList[Index2]; - mList[Index2]=temp; + PSynDocumentLine temp = mLines[Index1]; + mLines[Index1]=mLines[Index2]; + mLines[Index2]=temp; //mList.swapItemsAt(Index1,Index2); if (mIndexOfLongestLine == Index1) { mIndexOfLongestLine = Index2; @@ -377,10 +381,10 @@ void SynEditStringList::exchange(int Index1, int Index2) endUpdate(); } -void SynEditStringList::insert(int Index, const QString &s) +void SynDocument::insert(int Index, const QString &s) { QMutexLocker locker(&mMutex); - if ((Index < 0) || (Index > mList.count())) { + if ((Index < 0) || (Index > mLines.count())) { ListIndexOutOfBounds(Index); } beginUpdate(); @@ -389,10 +393,10 @@ void SynEditStringList::insert(int Index, const QString &s) endUpdate(); } -void SynEditStringList::deleteAt(int Index) +void SynDocument::deleteAt(int Index) { QMutexLocker locker(&mMutex); - if ((Index < 0) || (Index >= mList.count())) { + if ((Index < 0) || (Index >= mLines.count())) { ListIndexOutOfBounds(Index); } beginUpdate(); @@ -400,38 +404,38 @@ void SynEditStringList::deleteAt(int Index) mIndexOfLongestLine = -1; else if (mIndexOfLongestLine>Index) mIndexOfLongestLine -= 1; - mList.removeAt(Index); + mLines.removeAt(Index); emit deleted(Index,1); endUpdate(); } -QString SynEditStringList::getTextStr() const +QString SynDocument::getTextStr() const { QString result; - for (int i=0;ifString); result.append(lineBreak()); } - if (mList.length()>0) { - result.append(mList.back()->fString); + if (mLines.length()>0) { + result.append(mLines.back()->fString); } return result; } -void SynEditStringList::putString(int Index, const QString &s, bool notify) { +void SynDocument::putString(int Index, const QString &s, bool notify) { QMutexLocker locker(&mMutex); - if (Index == mList.count()) { + if (Index == mLines.count()) { add(s); } else { - if (Index<0 || Index>=mList.count()) { + if (Index<0 || Index>=mLines.count()) { ListIndexOutOfBounds(Index); } beginUpdate(); - int oldColumns = mList[Index]->fColumns; - mList[Index]->fString = s; + int oldColumns = mLines[Index]->fColumns; + mLines[Index]->fString = s; calculateLineColumns(Index); - if (oldColumns>mList[Index]->fColumns) + if (oldColumns>mLines[Index]->fColumns) mIndexOfLongestLine = -1; if (notify) emit putted(Index,1); @@ -439,18 +443,18 @@ void SynEditStringList::putString(int Index, const QString &s, bool notify) { } } -void SynEditStringList::putObject(int Index, void *AObject) +void SynDocument::putObject(int Index, void *AObject) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>=mList.count()) { + if (Index<0 || Index>=mLines.count()) { ListIndexOutOfBounds(Index); } beginUpdate(); - mList[Index]->fObject = AObject; + mLines[Index]->fObject = AObject; endUpdate(); } -void SynEditStringList::setUpdateState(bool Updating) +void SynDocument::setUpdateState(bool Updating) { if (Updating) emit changing(); @@ -458,18 +462,18 @@ void SynEditStringList::setUpdateState(bool Updating) emit changed(); } -int SynEditStringList::calculateLineColumns(int Index) +int SynDocument::calculateLineColumns(int Index) { - PSynEditStringRec line = mList[Index]; + PSynDocumentLine line = mLines[Index]; - line->fColumns = mEdit->stringColumns(line->fString,0); + line->fColumns = stringColumns(line->fString,0); return line->fColumns; } -void SynEditStringList::insertLines(int Index, int NumLines) +void SynDocument::insertLines(int Index, int NumLines) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>mList.count()) { + if (Index<0 || Index>mLines.count()) { ListIndexOutOfBounds(Index); } if (NumLines<=0) @@ -478,19 +482,19 @@ void SynEditStringList::insertLines(int Index, int NumLines) auto action = finally([this]{ endUpdate(); }); - PSynEditStringRec line; - mList.insert(Index,NumLines,line); + PSynDocumentLine line; + mLines.insert(Index,NumLines,line); for (int i=Index;i(); - mList[i]=line; + line = std::make_shared(); + mLines[i]=line; } emit inserted(Index,NumLines); } -void SynEditStringList::insertStrings(int Index, const QStringList &NewStrings) +void SynDocument::insertStrings(int Index, const QStringList &NewStrings) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>mList.count()) { + if (Index<0 || Index>mLines.count()) { ListIndexOutOfBounds(Index); } if (NewStrings.isEmpty()) @@ -499,20 +503,20 @@ void SynEditStringList::insertStrings(int Index, const QStringList &NewStrings) auto action = finally([this]{ endUpdate(); }); - PSynEditStringRec line; - mList.insert(Index,NewStrings.length(),line); + PSynDocumentLine line; + mLines.insert(Index,NewStrings.length(),line); for (int i=0;i(); + line = std::make_shared(); line->fString = NewStrings[i]; - mList[i+Index]=line; + mLines[i+Index]=line; } emit inserted(Index,NewStrings.length()); } -void SynEditStringList::insertText(int Index, const QString &NewText) +void SynDocument::insertText(int Index, const QString &NewText) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>=mList.count()) { + if (Index<0 || Index>=mLines.count()) { ListIndexOutOfBounds(Index); } if (NewText.isEmpty()) @@ -521,7 +525,7 @@ void SynEditStringList::insertText(int Index, const QString &NewText) insertStrings(Index,lines); } -bool SynEditStringList::tryLoadFileByEncoding(QByteArray encodingName, QFile& file) { +bool SynDocument::tryLoadFileByEncoding(QByteArray encodingName, QFile& file) { QTextCodec* codec = QTextCodec::codecForName(encodingName); if (!codec) return false; @@ -549,7 +553,26 @@ bool SynEditStringList::tryLoadFileByEncoding(QByteArray encodingName, QFile& fi } return true; } -void SynEditStringList::loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding) + +const QFontMetrics &SynDocument::fontMetrics() const +{ + return mFontMetrics; +} + +void SynDocument::setFontMetrics(const QFont &newFont) +{ + mFontMetrics = QFontMetrics(newFont); + mCharWidth = mFontMetrics.horizontalAdvance("M"); +} + +void SynDocument::setTabWidth(int newTabWidth) +{ + if (mTabWidth!=newTabWidth) { + mTabWidth = newTabWidth; + resetColumns(); + } +} +void SynDocument::loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding) { QMutexLocker locker(&mMutex); QFile file(filename); @@ -613,7 +636,7 @@ void SynEditStringList::loadFromFile(const QString& filename, const QByteArray& } line = file.readLine(); } - emit inserted(0,mList.count()); + emit inserted(0,mLines.count()); if (!needReread) { if (allAscii) realEncoding = ENCODING_ASCII; @@ -623,7 +646,7 @@ void SynEditStringList::loadFromFile(const QString& filename, const QByteArray& QList charsets = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName()); if (!charsets.isEmpty()) { if (tryLoadFileByEncoding(realEncoding,file)) { - emit inserted(0,mList.count()); + emit inserted(0,mLines.count()); return; } @@ -638,7 +661,7 @@ void SynEditStringList::loadFromFile(const QString& filename, const QByteArray& if (tryLoadFileByEncoding(encodingName,file)) { qDebug()<fString); } @@ -724,7 +747,31 @@ void SynEditStringList::saveToFile(QFile &file, const QByteArray& encoding, } } -void SynEditStringList::putTextStr(const QString &text) +int SynDocument::stringColumns(const QString &line, int colsBefore) const +{ + int columns = std::max(0,colsBefore); + int charCols; + for (int i=0;i 0 ) { - for (int i=0;ifColumns = -1; + if (mLines.count() > 0 ) { + for (int i=0;ifColumns = -1; } } } -void SynEditStringList::invalidAllLineColumns() +void SynDocument::invalidAllLineColumns() { QMutexLocker locker(&mMutex); mIndexOfLongestLine = -1; - for (PSynEditStringRec& line:mList) { + for (PSynDocumentLine& line:mLines) { line->fColumns = -1; } } -SynEditStringRec::SynEditStringRec(): +SynDocumentLine::SynDocumentLine(): fString(), fObject(nullptr), fRange{0,0,0,0,0}, diff --git a/RedPandaIDE/qsynedit/TextBuffer.h b/RedPandaIDE/qsynedit/TextBuffer.h index 4c2b4b63..b659260f 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.h +++ b/RedPandaIDE/qsynedit/TextBuffer.h @@ -19,6 +19,7 @@ #include #include "highlighter/base.h" +#include #include #include #include @@ -34,36 +35,33 @@ enum SynEditStringFlag { typedef int SynEditStringFlags; -struct SynEditStringRec { +struct SynDocumentLine { QString fString; void * fObject; SynRangeState fRange; int fColumns; // public: - explicit SynEditStringRec(); + explicit SynDocumentLine(); }; -typedef std::shared_ptr PSynEditStringRec; +typedef std::shared_ptr PSynDocumentLine; -typedef QVector SynEditStringRecList; +typedef QVector SynDocumentLines; -typedef std::shared_ptr PSynEditStringRecList; +typedef std::shared_ptr PSynDocumentLines; -class SynEditStringList; +class SynDocument; -typedef std::shared_ptr PSynEditStringList; - -using StringListChangeCallback = std::function; +typedef std::shared_ptr PSynDocument; class QFile; -class SynEdit; -class SynEditStringList : public QObject +class SynDocument : public QObject { Q_OBJECT public: - explicit SynEditStringList(SynEdit* pEdit,QObject* parent=nullptr); + explicit SynDocument(const QFont& font, QObject* parent=nullptr); int parenthesisLevels(int Index); int bracketLevels(int Index); @@ -104,6 +102,8 @@ public: void loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding); void saveToFile(QFile& file, const QByteArray& encoding, const QByteArray& defaultEncoding, QByteArray& realEncoding); + int stringColumns(const QString& line, int colsBefore) const; + int charColumns(QChar ch) const; bool getAppendNewLineAtEOF(); void setAppendNewLineAtEOF(bool appendNewLineAtEOF); @@ -114,6 +114,14 @@ public: bool empty(); void resetColumns(); + int tabWidth() const { + return mTabWidth; + } + void setTabWidth(int newTabWidth); + + const QFontMetrics &fontMetrics() const; + void setFontMetrics(const QFont &newFont); + public slots: void invalidAllLineColumns(); @@ -135,9 +143,13 @@ private: bool tryLoadFileByEncoding(QByteArray encodingName, QFile& file); private: - SynEditStringRecList mList; + SynDocumentLines mLines; - SynEdit* mEdit; + //SynEdit* mEdit; + + QFontMetrics mFontMetrics; + int mTabWidth; + int mCharWidth; //int mCount; //int mCapacity; FileEndingType mFileEndingType; diff --git a/RedPandaIDE/qsynedit/TextPainter.cpp b/RedPandaIDE/qsynedit/TextPainter.cpp index a28a9213..726d1a9f 100644 --- a/RedPandaIDE/qsynedit/TextPainter.cpp +++ b/RedPandaIDE/qsynedit/TextPainter.cpp @@ -128,7 +128,7 @@ void SynEditTextPainter::paintGutter(const QRect& clip) BufferCoord selectionEnd = edit->blockEnd(); for (int cRow = aFirstRow; cRow <= aLastRow; cRow++) { vLine = edit->rowToLine(cRow); - if ((vLine > edit->mLines->count()) && (edit->mLines->count() > 0 )) + if ((vLine > edit->mDocument->count()) && (edit->mDocument->count() > 0 )) break; if (edit->mGutter.activeLineTextColor().isValid()) { if ( @@ -164,7 +164,7 @@ void SynEditTextPainter::paintGutter(const QRect& clip) if (edit->mUseCodeFolding) { for (cRow = aLastRow; cRow>=aFirstRow; cRow--) { vLine = edit->rowToLine(cRow); - if ((vLine > edit->mLines->count()) && (edit->mLines->count() != 0)) + if ((vLine > edit->mDocument->count()) && (edit->mDocument->count() != 0)) continue; // Form a rectangle for the square the user can click on @@ -229,7 +229,7 @@ void SynEditTextPainter::paintGutter(const QRect& clip) for (cRow = aFirstRow; cRow <=aLastRow; cRow++) { vLine = edit->rowToLine(cRow); - if ((vLine > edit->mLines->count()) && (edit->mLines->count() != 0)) + if ((vLine > edit->mDocument->count()) && (edit->mDocument->count() != 0)) break; edit->onGutterPaint(*painter,vLine, 0, (cRow - edit->mTopLine) * edit->mTextHeight); } @@ -359,7 +359,7 @@ void SynEditTextPainter::PaintToken(const QString &Token, int TokenCols, int Col int charCols=0; QString textToPaint = Token[i]; if (Token[i] == SynTabChar) { - charCols = edit->mTabWidth - ((ColumnsBefore+tokenColLen) % edit->mTabWidth); + charCols = edit->tabWidth() - ((ColumnsBefore+tokenColLen) % edit->tabWidth()); } else { charCols = edit->charColumns(Token[i]); } @@ -675,7 +675,7 @@ void SynEditTextPainter::PaintFoldAttributes() // Now loop through all the lines. The indices are valid for Lines. for (cRow = aFirstRow; cRow<=aLastRow;cRow++) { vLine = edit->rowToLine(cRow); - if (vLine > edit->mLines->count() && edit->mLines->count() > 0) + if (vLine > edit->mDocument->count() && edit->mDocument->count() > 0) break; // Set vertical coord Y = (cRow - edit->mTopLine) * edit->mTextHeight; // limit inside clip rect @@ -684,15 +684,15 @@ void SynEditTextPainter::PaintFoldAttributes() } // Get next nonblank line LastNonBlank = vLine - 1; - while (LastNonBlank + 1 < edit->mLines->count() && edit->mLines->getString(LastNonBlank).isEmpty()) + while (LastNonBlank + 1 < edit->mDocument->count() && edit->mDocument->getString(LastNonBlank).isEmpty()) LastNonBlank++; - if (LastNonBlank>=edit->lines()->count()) + if (LastNonBlank>=edit->document()->count()) continue; - LineIndent = edit->getLineIndent(edit->mLines->getString(LastNonBlank)); - int braceLevel = edit->mLines->ranges(LastNonBlank).braceLevel; + LineIndent = edit->getLineIndent(edit->mDocument->getString(LastNonBlank)); + int braceLevel = edit->mDocument->ranges(LastNonBlank).braceLevel; int indentLevel = braceLevel ; - if (edit->mTabWidth>0) - indentLevel = LineIndent / edit->mTabWidth; + if (edit->tabWidth()>0) + indentLevel = LineIndent / edit->tabWidth(); int levelDiff = std::max(0,braceLevel - indentLevel); // Step horizontal coord //TabSteps = edit->mTabWidth; @@ -701,7 +701,7 @@ void SynEditTextPainter::PaintFoldAttributes() while (TabSteps < LineIndent) { X = TabSteps * edit->mCharWidth + edit->textOffset() - 2; - TabSteps+=edit->mTabWidth; + TabSteps+=edit->tabWidth(); indentLevel++ ; if (edit->mHighlighter) { if (edit->mCodeFolding.indentGuides) { @@ -815,11 +815,11 @@ void SynEditTextPainter::PaintLines() BufferCoord selectionEnd= edit->blockEnd(); for (cRow = aFirstRow; cRow<=aLastRow; cRow++) { vLine = edit->rowToLine(cRow); - if (vLine > edit->mLines->count() && edit->mLines->count() != 0) + if (vLine > edit->mDocument->count() && edit->mDocument->count() != 0) break; // Get the line. - sLine = edit->mLines->getString(vLine - 1); + 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); @@ -892,7 +892,7 @@ void SynEditTextPainter::PaintLines() if (bCurrentLine) { nTokenColumnLen = edit->stringColumns(sLine,0); } else { - nTokenColumnLen = edit->mLines->lineColumns(vLine-1); + nTokenColumnLen = edit->mDocument->lineColumns(vLine-1); } if (edit->mOptions.testFlag(eoShowSpecialChars) && (!bLineSelected) && (!bSpecialLine) && (nTokenColumnLen < vLastChar)) { sToken = sToken + SynLineBreakGlyph; @@ -932,7 +932,7 @@ void SynEditTextPainter::PaintLines() edit->mHighlighter->resetState(); } else { edit->mHighlighter->setState( - edit->mLines->ranges(vLine-2)); + edit->mDocument->ranges(vLine-2)); } edit->mHighlighter->setLine(sLine, vLine - 1); // Try to concatenate as many tokens as possible to minimize the count @@ -1008,7 +1008,7 @@ void SynEditTextPainter::PaintLines() // Don't assume HL.GetTokenPos is valid after HL.GetEOL == True. //nTokenColumnsBefore += edit->stringColumns(sToken,nTokenColumnsBefore); if (edit->mHighlighter->eol() && (nTokenColumnsBefore < vLastChar)) { - int lineColumns = edit->mLines->lineColumns(vLine-1); + int lineColumns = edit->mDocument->lineColumns(vLine-1); // Draw text that couldn't be parsed by the highlighter, if any. if (nTokenColumnsBefore < lineColumns) { if (nTokenColumnsBefore + 1 < vFirstChar) @@ -1022,9 +1022,9 @@ void SynEditTextPainter::PaintLines() } // Draw LineBreak glyph. if (edit->mOptions.testFlag(eoShowSpecialChars) && (!bLineSelected) && - (!bSpecialLine) && (edit->mLines->lineColumns(vLine-1) < vLastChar)) { + (!bSpecialLine) && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) { AddHighlightToken(SynLineBreakGlyph, - edit->mLines->lineColumns(vLine-1) - (vFirstChar - FirstCol), + edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol), edit->charColumns(SynLineBreakGlyph),vLine, edit->mHighlighter->whitespaceAttribute()); } } @@ -1033,10 +1033,10 @@ void SynEditTextPainter::PaintLines() foldRange = edit->foldStartAtLine(vLine); if ((foldRange) && foldRange->collapsed) { sFold = " ... } "; - nFold = edit->stringColumns(sFold,edit->mLines->lineColumns(vLine-1)); + nFold = edit->stringColumns(sFold,edit->mDocument->lineColumns(vLine-1)); attr = edit->mHighlighter->symbolAttribute(); GetBraceColorAttr(edit->mHighlighter->getRangeState().braceLevel,attr); - AddHighlightToken(sFold,edit->mLines->lineColumns(vLine-1)+1 - (vFirstChar - FirstCol) + AddHighlightToken(sFold,edit->mDocument->lineColumns(vLine-1)+1 - (vFirstChar - FirstCol) , nFold, vLine, attr); } diff --git a/RedPandaIDE/qsynedit/Types.cpp b/RedPandaIDE/qsynedit/Types.cpp index 47befe1b..3e132f7d 100644 --- a/RedPandaIDE/qsynedit/Types.cpp +++ b/RedPandaIDE/qsynedit/Types.cpp @@ -28,7 +28,7 @@ ContentsCoord::ContentsCoord(const SynEdit *edit, int ch, int line) void ContentsCoord::normalize() { - if (mEdit->lines()->count()==0) { + if (mEdit->document()->count()==0) { mChar = 0; mLine = 0; return; @@ -36,9 +36,9 @@ void ContentsCoord::normalize() int aLine = mLine; int aChar = mChar; int line = aLine-1; - int lineCount = mEdit->lines()->count(); + int lineCount = mEdit->document()->count(); if (line>=lineCount) { - mChar = mEdit->lines()->getString(lineCount-1).length()+1; + mChar = mEdit->document()->getString(lineCount-1).length()+1; mLine = lineCount; return; } @@ -55,7 +55,7 @@ void ContentsCoord::normalize() mLine = 0; return; } - QString s = mEdit->lines()->getString(line); + QString s = mEdit->document()->getString(line); int len = s.length(); aChar+=len+1; if (aChar>=1) { @@ -64,7 +64,7 @@ void ContentsCoord::normalize() } } else { while (true) { - QString s =mEdit->lines()->getString(line); + QString s =mEdit->document()->getString(line); int len = s.length(); if (aChar<=len+1) { break; @@ -101,7 +101,7 @@ bool ContentsCoord::atStart() bool ContentsCoord::atEnd() { Q_ASSERT(mEdit!=nullptr); - return mLine>mEdit->lines()->count(); + return mLine>mEdit->document()->count(); } const SynEdit *ContentsCoord::edit() const @@ -164,13 +164,13 @@ size_t ContentsCoord::operator-(const ContentsCoord& coord) const if (mLine == coord.mLine) { return mChar - coord.mChar; } else if (mLine > coord.mLine) { - size_t result = mEdit->lines()->getString(coord.mLine-1).length()+1-coord.mChar; + size_t result = mEdit->document()->getString(coord.mLine-1).length()+1-coord.mChar; int line = coord.mLine+1; while (line<=mLine-1) { - result += mEdit->lines()->getString(line-1).length()+1; + result += mEdit->document()->getString(line-1).length()+1; line++; } - if (mLine<=mEdit->lines()->count()) { + if (mLine<=mEdit->document()->count()) { result += mChar; } return result; @@ -216,10 +216,10 @@ QChar ContentsCoord::operator*() const if (mLine < 1) { return QChar('\0'); } - if (mLine > mEdit->lines()->count()) { + if (mLine > mEdit->document()->count()) { return QChar('\0'); } - QString s = mEdit->lines()->getString(mLine-1); + QString s = mEdit->document()->getString(mLine-1); if (mChar >= s.length()+1 ) { return QChar('\n'); } diff --git a/RedPandaIDE/qsynedit/exporter/synexporter.cpp b/RedPandaIDE/qsynedit/exporter/synexporter.cpp index 3ee20c71..8bc645f4 100644 --- a/RedPandaIDE/qsynedit/exporter/synexporter.cpp +++ b/RedPandaIDE/qsynedit/exporter/synexporter.cpp @@ -53,12 +53,12 @@ void SynExporter::CopyToClipboard() CopyToClipboardFormat(clipboardFormat()); } -void SynExporter::ExportAll(PSynEditStringList ALines) +void SynExporter::ExportAll(PSynDocument ALines) { ExportRange(ALines, BufferCoord{1, 1}, BufferCoord{INT_MAX, INT_MAX}); } -void SynExporter::ExportRange(PSynEditStringList ALines, BufferCoord Start, BufferCoord Stop) +void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoord Stop) { // abort if not all necessary conditions are met if (!ALines || !mHighlighter || (ALines->count() == 0)) diff --git a/RedPandaIDE/qsynedit/exporter/synexporter.h b/RedPandaIDE/qsynedit/exporter/synexporter.h index d87e81a1..f16e39db 100644 --- a/RedPandaIDE/qsynedit/exporter/synexporter.h +++ b/RedPandaIDE/qsynedit/exporter/synexporter.h @@ -44,7 +44,7 @@ public: * @brief Exports everything in the strings parameter to the output buffer. * @param ALines */ - void ExportAll(PSynEditStringList ALines); + void ExportAll(PSynDocument ALines); /** * @brief Exports the given range of the strings parameter to the output buffer. @@ -52,7 +52,7 @@ public: * @param Start * @param Stop */ - void ExportRange(PSynEditStringList ALines, + void ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoord Stop); /** * @brief Saves the contents of the output buffer to a file. diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index d4f0713d..02ecce09 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -63,7 +63,7 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr this, &EditorColorSchemeWidget::onItemSelectionChanged); connect(this, &SettingsWidget::settingsChanged,this, &EditorColorSchemeWidget::onSettingChanged); - ui->editDemo->lines()->setText( + ui->editDemo->document()->setText( "#include \n" "#include \n" "\n" diff --git a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp index b47e18ff..868c2bd2 100644 --- a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp @@ -46,12 +46,12 @@ EditorSnippetWidget::EditorSnippetWidget(const QString& name, const QString& gro QModelIndex index = ui->tblSnippets->currentIndex(); if (!index.isValid()) { ui->editCode->setEnabled(false); - ui->editCode->lines()->clear(); + ui->editCode->document()->clear(); } else { mUpdatingCode = true; ui->editCode->setEnabled(true); PCodeSnippet snippet = mModel.snippets()[index.row()]; - ui->editCode->lines()->setText(snippet->code); + ui->editCode->document()->setText(snippet->code); mUpdatingCode = false; } }); @@ -67,7 +67,7 @@ EditorSnippetWidget::~EditorSnippetWidget() void EditorSnippetWidget::doLoad() { mModel.updateSnippets(pMainWindow->codeSnippetManager()->snippets()); - ui->editFileTemplate->lines()->setText(pMainWindow->codeSnippetManager()->newFileTemplate()); + ui->editFileTemplate->document()->setText(pMainWindow->codeSnippetManager()->newFileTemplate()); } void EditorSnippetWidget::doSave() diff --git a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp index eb45eeb5..5088803c 100644 --- a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp @@ -325,7 +325,7 @@ void FormatterGeneralWidget::updateDemo() pSettings->dirs().appDir(), formatter.getArguments(), content); - ui->editDemo->lines()->setText(newContent); + ui->editDemo->document()->setText(newContent); } void FormatterGeneralWidget::updateCodeFormatter(Settings::CodeFormatter &format) diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp index f2a908b9..0dd2b789 100644 --- a/RedPandaIDE/widgets/cpudialog.cpp +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -114,13 +114,13 @@ void CPUDialog::setDisassembly(const QString& file, const QString& funcName,cons { ui->txtFunctionName->setText(QString("%1:%2").arg(file, funcName)); int activeLine = -1; - ui->txtCode->lines()->clear(); + ui->txtCode->document()->clear(); for (int i=0;i")) { activeLine = i; } - ui->txtCode->lines()->add(line); + ui->txtCode->document()->add(line); } if (activeLine!=-1) ui->txtCode->setCaretXYEx(true,BufferCoord{1,activeLine+1}); diff --git a/RedPandaIDE/widgets/filepropertiesdialog.cpp b/RedPandaIDE/widgets/filepropertiesdialog.cpp index 80e49911..ce8c1738 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.cpp +++ b/RedPandaIDE/widgets/filepropertiesdialog.cpp @@ -44,14 +44,14 @@ void FilePropertiesDialog::calcFile(Editor *editor, int &codeLines, int &includeLines) { - totalLines = editor->lines()->count(); + totalLines = editor->document()->count(); codeLines = 0; commentLines = 0; emptyLines = 0; includeLines = 0; // iterate through all lines of file - for (int i=0;ilines()->count();i++) { - QString line = editor->lines()->getString(i); + for (int i=0;idocument()->count();i++) { + QString line = editor->document()->getString(i); int j=0; while (jtxtProject->setText("-"); ui->txtPath->setText(editor->filename()); ui->txtRelativeToProject->setText("_"); - ui->txtLines->setText(QString("%1").arg(editor->lines()->count())); + ui->txtLines->setText(QString("%1").arg(editor->document()->count())); int totalLines, codeLines,emptyLines,commentLines,includeLines; calcFile(editor,totalLines,commentLines,emptyLines,codeLines,includeLines); diff --git a/RedPandaIDE/widgets/searchdialog.cpp b/RedPandaIDE/widgets/searchdialog.cpp index 21c79446..e5eb6f56 100644 --- a/RedPandaIDE/widgets/searchdialog.cpp +++ b/RedPandaIDE/widgets/searchdialog.cpp @@ -380,7 +380,7 @@ void SearchDialog::on_btnExecute_clicked() } else if (fileExists(curFilename)) { SynEdit editor; QByteArray realEncoding; - editor.lines()->loadFromFile(curFilename,ENCODING_AUTO_DETECT, realEncoding); + editor.document()->loadFromFile(curFilename,ENCODING_AUTO_DETECT, realEncoding); fileSearched++; PSearchResultTreeItem parentItem = batchFindInEditor( &editor, @@ -449,7 +449,7 @@ std::shared_ptr SearchDialog::batchFindInEditor(SynEdit *e item->start = ch; item->len = wordLen; item->parent = parentItem.get(); - item->text = e->lines()->getString(Line-1); + item->text = e->document()->getString(Line-1); item->text.replace('\t',' '); parentItem->results.append(item); return SynSearchAction::Skip;