diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index 29912461..46a81e92 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -146,13 +146,11 @@ int Document::blockEnded(int line) int Document::maxLineWidth() { QMutexLocker locker(&mMutex); if (mIndexOfLongestLine < 0) { - qDebug()<<"!!!!"; int MaxLen = -1; mIndexOfLongestLine = -1; if (mLines.count() > 0 ) { for (int i=0;imWidth; - qDebug()< MaxLen) { MaxLen = len; mIndexOfLongestLine = i; @@ -161,7 +159,6 @@ int Document::maxLineWidth() { } } if (mIndexOfLongestLine >= 0) { - qDebug()<getLine(mIndexOfLongestLine); return mLines[mIndexOfLongestLine]->width(); } else return -1; @@ -197,8 +194,8 @@ void Document::insertItem(int line, const QString &s) PDocumentLine documentLine = std::make_shared( mUpdateDocumentLineWidthFunc); documentLine->setLineText(s); - mIndexOfLongestLine = -1; mLines.insert(line,documentLine); + setIndexOfLongestLine(-1); endUpdate(); } @@ -207,7 +204,6 @@ void Document::addItem(const QString &s) beginUpdate(); PDocumentLine line = std::make_shared(mUpdateDocumentLineWidthFunc); line->setLineText(s); - mIndexOfLongestLine = -1; mLines.append(line); endUpdate(); } @@ -287,13 +283,13 @@ void Document::setContents(const QStringList &text) }); internalClear(); if (text.count() > 0) { - mIndexOfLongestLine = -1; int FirstAdded = mLines.count(); foreach (const QString& s,text) { addItem(s); } emit inserted(FirstAdded,text.count()); + setIndexOfLongestLine(-1); } } @@ -340,16 +336,15 @@ void Document::addLines(const QStringList &strings) { QMutexLocker locker(&mMutex); if (strings.count() > 0) { - mIndexOfLongestLine = -1; beginUpdate(); auto action = finally([this]{ endUpdate(); }); int FirstAdded = mLines.count(); - for (const QString& s:strings) { addItem(s); } + setIndexOfLongestLine(-1); emit inserted(FirstAdded,strings.count()); } } @@ -389,7 +384,7 @@ void Document::deleteLines(int index, int numLines) }); if (mIndexOfLongestLine>=index) { if (mIndexOfLongestLine index) - invalidateIndexOfLongestLine(); + setIndexOfLongestLine(-1); mLines.removeAt(index); emit deleted(index,1); endUpdate(); @@ -475,12 +470,15 @@ void Document::putLine(int index, const QString &s, bool notify) { listIndexOutOfBounds(index); } beginUpdate(); - int oldWidth = -1; - if (mIndexOfLongestLine == index) - oldWidth = mLines[index]->mWidth; - mLines[index]->setLineText( s ); - if (mIndexOfLongestLine == index && oldWidth>mLines[index]->width() ) - invalidateIndexOfLongestLine(); + int oldMaxWidth = maxLineWidth(); + mLines[index]->setLineText(s); + int newWidth = mLines[index]->width(true); + if (mIndexOfLongestLine == index && oldMaxWidth>newWidth ) { + setIndexOfLongestLine(-1); + } else { + if (newWidth > oldMaxWidth) + setIndexOfLongestLine(index); + } if (notify) emit putted(index); endUpdate(); @@ -505,7 +503,7 @@ void Document::insertLines(int index, int numLines) return; beginUpdate(); auto action = finally([this]{ - invalidateIndexOfLongestLine(); + setIndexOfLongestLine(-1); endUpdate(); }); PDocumentLine line; @@ -636,7 +634,7 @@ void Document::loadFromFile(const QString& filename, const QByteArray& encoding, auto action = finally([this]{ if (mLines.count()>0) emit inserted(0,mLines.count()); - invalidateIndexOfLongestLine(); + setIndexOfLongestLine(-1); endUpdate(); }); //test for utf8 / utf 8 bom @@ -1165,7 +1163,7 @@ void Document::internalClear() beginUpdate(); int oldCount = mLines.count(); mLines.clear(); - invalidateIndexOfLongestLine(); + setIndexOfLongestLine(-1); emit deleted(0,oldCount); endUpdate(); } @@ -1213,17 +1211,17 @@ void Document::emitMaxLineWidthChanged() void Document::updateLongestLineWidth(int line, int width) { if (mIndexOfLongestLine<0) { - mIndexOfLongestLine = line; - emitMaxLineWidthChanged(); + setIndexOfLongestLine(line); } else if (mLines[mIndexOfLongestLine]->mWidth < width) { - mIndexOfLongestLine = line; - emitMaxLineWidthChanged(); + setIndexOfLongestLine(line); } } -void Document::invalidateIndexOfLongestLine() +void Document::setIndexOfLongestLine(int line) { - mIndexOfLongestLine = -1; + mIndexOfLongestLine = line; + //mIndexOfLongestLine may not change, but it's width changed. + //so we must emit the signal here emitMaxLineWidthChanged(); } @@ -1279,9 +1277,8 @@ void Document::invalidateAllLineWidth() QMutexLocker locker(&mMutex); for (PDocumentLine& line:mLines) { line->invalidateWidth(); - qDebug()<mWidth<mLineText<<"invalidated"; } - invalidateIndexOfLongestLine(); + setIndexOfLongestLine(-1); // mIndexOfLongestLine = -1; } @@ -1322,9 +1319,9 @@ int DocumentLine::glyphWidth(int i) return calcSegmentInterval(mGlyphStartPositionList, mWidth, i); } -int DocumentLine::width() +int DocumentLine::width(bool forceUpdate) { - if(mWidth<0) + if(mWidth<0 || forceUpdate) updateWidth(); return mWidth; } diff --git a/libs/qsynedit/qsynedit/document.h b/libs/qsynedit/qsynedit/document.h index a33aa245..3a1d9a1b 100644 --- a/libs/qsynedit/qsynedit/document.h +++ b/libs/qsynedit/qsynedit/document.h @@ -132,7 +132,7 @@ private: * @brief get the width (pixel) of the line text * @return the width (in width) */ - int width(); + int width(bool forceUpdate=false); /** * @brief get the state of the syntax highlighter after this line is parsed @@ -581,7 +581,7 @@ private: void setLineWidth(int line, const QString& lineText, int newWidth, const QList glyphStartPositionList); void emitMaxLineWidthChanged(); void updateLongestLineWidth(int line, int width); - void invalidateIndexOfLongestLine(); + void setIndexOfLongestLine(int line); int glyphWidth(const QString& glyph, int left, const QFontMetrics &fontMetrics, diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index ac62a91d..c0b83e7c 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -288,9 +288,8 @@ bool QSynEdit::canRedo() const int QSynEdit::maxScrollWidth() const { int maxWidth = mDocument->maxLineWidth(); - qDebug()<foldString(""),maxWidth); if (mOptions.testFlag(eoScrollPastEol)) @@ -704,9 +703,7 @@ DisplayCoord QSynEdit::bufferToDisplayPos(const BufferCoord &p) const // Account for tabs and charColumns if (p.line-1 count()) result.x = charToGlyphLeft(p.line,p.ch); - // Account for code folding - if (useCodeFolding()) - result.row = foldLineToRow(result.row); + result.row = lineToRow(result.row); return result; } @@ -867,7 +864,10 @@ int QSynEdit::rowToLine(int aRow) const int QSynEdit::lineToRow(int aLine) const { - return bufferToDisplayPos({1, aLine}).row; + if (useCodeFolding()) + return foldLineToRow(aLine); + else + return aLine; } int QSynEdit::foldRowToLine(int row) const @@ -3092,7 +3092,7 @@ void QSynEdit::updateHScrollbar() mStateFlags.setFlag(StateFlag::sfHScrollbarChanged); } else { mStateFlags.setFlag(StateFlag::sfHScrollbarChanged,false); - updateHScrollBarLater(); + doUpdateHScrollbar(); } } @@ -3100,6 +3100,8 @@ void QSynEdit::doUpdateHScrollbar() { int nMin = 0; int nMax = maxScrollWidth(); + if (nMax<0) + return; int nPage = viewWidth(); int nPos = mLeftPos; horizontalScrollBar()->setMinimum(nMin); @@ -5951,6 +5953,8 @@ void QSynEdit::resizeEvent(QResizeEvent *) void QSynEdit::timerEvent(QTimerEvent *event) { if (event->timerId() == m_blinkTimerId) { + if (mPaintLock>0) + return; m_blinkStatus = 1- m_blinkStatus; updateCaret(); } @@ -6801,7 +6805,6 @@ void QSynEdit::setLeftPos(int value) if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) horizontalScrollBar()->setValue(value); else { - mLeftPos = value; invalidate(); } }