diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index c435c9d0..2f6fb2de 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -123,7 +123,7 @@ int Document::blockEnded(int index) return 0; } -int Document::lengthOfLongestLine() { +int Document::longestLineColumns() { QMutexLocker locker(&mMutex); if (mIndexOfLongestLine < 0) { int MaxLen = -1; @@ -139,7 +139,7 @@ int Document::lengthOfLongestLine() { } } if (mIndexOfLongestLine >= 0) - return mLines[mIndexOfLongestLine]->columns; + return mLines[mIndexOfLongestLine]->columns(); else return 0; } @@ -211,13 +211,31 @@ void Document::setSyntaxState(int Index, const SyntaxState& range) //endUpdate(); } -QString Document::getLine(int Index) +QString Document::getLine(int index) { QMutexLocker locker(&mMutex); - if (Index<0 || Index>=mLines.count()) { + if (index<0 || index>=mLines.count()) { return QString(); } - return mLines[Index]->lineText; + return mLines[index]->lineText(); +} + +int Document::getLineGlyphsCount(int index) +{ + QMutexLocker locker(&mMutex); + if (index<0 || index>=mLines.count()) { + return 0; + } + return mLines[index]->glyphsCount(); +} + +const QList &Document::getGlyphPositions(int index) +{ + QMutexLocker locker(&mMutex); + if (index<0 || index>=mLines.count()) { + return QList{}; + } + return mLines[index]->glyphPositions(); } int Document::count() @@ -578,7 +596,7 @@ void Document::setTabWidth(int newTabWidth) { if (mTabWidth!=newTabWidth) { mTabWidth = newTabWidth; - resetColumns(); + invalidateAllLineColumns(); } } @@ -789,10 +807,10 @@ void Document::saveToFile(QFile &file, const QByteArray& encoding, } } -int Document::gryphsColumns(const QStringList &gryphs, int colsBefore) const +int Document::gryphsColumns(const QString& lineText, const QList &glyphPositions, int colsBefore) const { int columns = std::max(0,colsBefore); - for (int i=0;i 0 ) { - for (int i=0;icolumns = -1; - } - } -} - -void Document::invalidAllLineColumns() +void Document::invalidateAllLineColumns() { QMutexLocker locker(&mMutex); mIndexOfLongestLine = -1; for (PDocumentLine& line:mLines) { - line->columns = -1; + line->invalidateColumns(); } } @@ -946,49 +953,40 @@ DocumentLine::DocumentLine(): { } -const QStringList &DocumentLine::glyphs() const +QStringRef DocumentLine::getGlyph(int i) const { - return mGlyphs; -} - -int DocumentLine::length() const -{ - return mGlyphs.length(); -} - -const QString& DocumentLine::lineText() const -{ - return mLineText; + Q_ASSERT(i>=0 && i0) { - //Combining character - QString gryph=mGryphs.last(); - gryph.append(mLineText[i]); - mGryphs[mGryphs.length()-1]=gryph; + } else if (ch.combiningClass()!=0 && !mGlyphPositions.isEmpty()) { + //a Combining character } else { - mGryphs.append(mLineText[i]); + mGlyphPositions.append(i); } i++; } } -int DocumentLine::columns() const -{ - return mColumns; -} - const SyntaxState& DocumentLine::syntaxState() const { return mSyntaxState; diff --git a/libs/qsynedit/qsynedit/document.h b/libs/qsynedit/qsynedit/document.h index 5ea2464f..38a57318 100644 --- a/libs/qsynedit/qsynedit/document.h +++ b/libs/qsynedit/qsynedit/document.h @@ -30,28 +30,33 @@ namespace QSynedit { +class Document; + class DocumentLine { public: explicit DocumentLine(); DocumentLine(const DocumentLine&)=delete; DocumentLine& operator=(const DocumentLine&)=delete; - const QStringList& glyphs() const; - int length() const; + int glyphsCount() const { return mGlyphPositions.length(); } + const QList& glyphPositions() const { return mGlyphPositions; } + QStringRef getGlyph(int i) const; - const QString& lineText() const; - void setLineText(const QString &newLineText); + const QString& lineText() const { return mLineText; } - int columns() const; + int columns() const { return mColumns; } const SyntaxState& syntaxState() const; void setSyntaxState(const SyntaxState &newSyntaxState); - private: - QString mLineText; - QStringList mGlyphs; - SyntaxState mSyntaxState; - int mColumns; + void setLineText(const QString &newLineText); + void invalidateColumns() { mColumns = -1; } +private: + QString mLineText; + QList mGlyphPositions; + SyntaxState mSyntaxState; + int mColumns; + friend class Document; }; typedef std::shared_ptr PDocumentLine; @@ -60,8 +65,6 @@ typedef QVector DocumentLines; typedef std::shared_ptr PDocumentLines; -class Document; - typedef std::shared_ptr PDocument; class BinaryFileError : public FileError { @@ -84,11 +87,13 @@ public: int blockLevel(int index); int blockStarted(int index); int blockEnded(int index); - int lengthOfLongestLine(); + int longestLineColumns(); QString lineBreak() const; SyntaxState getSyntaxState(int index); void setSyntaxState(int index, const SyntaxState& range); QString getLine(int index); + int getLineGlyphsCount(int index); + const QList& getGlyphPositions(int index); int count(); QString text(); void setText(const QString& text); @@ -115,7 +120,7 @@ public: void saveToFile(QFile& file, const QByteArray& encoding, const QByteArray& defaultEncoding, QByteArray& realEncoding); //int stringColumns(const QString &line, int colsBefore) const; - int gryphsColumns(const QStringList& gryphs, int colsBefore) const; + int gryphsColumns(const QString& lineText, const QList &glyphPositions, int colsBefore) const; int tokenColumns(const QString &token) const; int charColumns(QChar ch) const; @@ -127,7 +132,6 @@ public: bool empty(); - void resetColumns(); int tabWidth() const { return mTabWidth; } @@ -137,7 +141,7 @@ public: void setFontMetrics(const QFont &newFont, const QFont& newNonAsciiFont); public slots: - void invalidAllLineColumns(); + void invalidateAllLineColumns(); signals: void changed(); diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index e3734b37..c65cd0e9 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -327,7 +327,7 @@ bool QSynEdit::canRedo() const int QSynEdit::maxScrollWidth() const { - int maxLen = mDocument->lengthOfLongestLine(); + int maxLen = mDocument->longestLineColumns(); if (syntaxer()) maxLen = maxLen+stringColumns(syntaxer()->foldString(""),maxLen); if (mOptions.testFlag(eoScrollPastEol)) @@ -6780,7 +6780,7 @@ void QSynEdit::setBlockEnd(BufferCoord value) else value.ch = 1; } else { - int maxLen = mDocument->lengthOfLongestLine(); + int maxLen = mDocument->longestLineColumns(); if (syntaxer()) maxLen = maxLen+stringColumns(syntaxer()->foldString(""),maxLen); value.ch = minMax(value.ch, 1, maxLen+1); @@ -6887,7 +6887,7 @@ void QSynEdit::setBlockBegin(BufferCoord value) else value.ch = 1; } else { - int maxLen = mDocument->lengthOfLongestLine(); + int maxLen = mDocument->longestLineColumns(); if (syntaxer()) maxLen = maxLen+stringColumns(syntaxer()->foldString(""),maxLen); value.ch = minMax(value.ch, 1, maxLen+1);