diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index 18b5ef79..eef84359 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -93,6 +93,22 @@ int Document::lineColumns(int index) return 0; } +int Document::lineColumns(int index, const QString &newText) +{ + QMutexLocker locker(&mMutex); + if (index<0 || index >= mLines.size()) + return 0; + QString lineText = mLines[index]; + if (lineText==newText) { + if (mLines[index]->columns() == -1) { + return calculateLineColumns(index); + } else + return mLines[index]->columns(); + } else { + return stringColumns(newText,0); + } +} + int Document::blockLevel(int index) { QMutexLocker locker(&mMutex); @@ -479,8 +495,10 @@ void Document::setUpdateState(bool Updating) int Document::calculateLineColumns(int Index) { PDocumentLine line = mLines[Index]; - - line->setColumns( glyphsColumns(line->lineText(), line->glyphPositions(), 0)); + QList glyphColumns; + int columns; + glyphColumns = calcGlyphColumns(line->lineText(), line->glyphPositions(), 0, columns); + line->setColumns(columns, glyphColumns); return line->columns(); } @@ -836,32 +854,64 @@ int Document::stringColumns(const QString &line, int colsBefore) const int Document::glyphsColumns(const QString& lineText, const QList &glyphPositions, int colsBefore) const { - int columns = std::max(0,colsBefore); - int start,end; - for (int i=0;i=0 && index < mLines.size()) { + return 0; } - return columns-colsBefore; + QString lineText = mLines[line]->lineText(); + if (lineText == newText) { + QList glyphPositions = mLines[line]->lineText(); + return glyphsColumns(lineText, glyphPositions, colsBefore); + } else { + return stringColumns(newText, colsBefore); + } +} + +int Document::glyphsColumns(int line, int colsBefore) +{ + QMutexLocker locker(&mMutex); + if (index>=0 && index < mLines.size()) { + return 0; + } + QString lineText = mLines[line]->lineText(); + QList glyphPositions = mLines[line]->lineText(); + return glyphsColumns(lineText, glyphPositions, colsBefore); +} + +int Document::charToColumn(const QString &lineText, int charPos) const +{ + QList glyphPositions = calcGlyphPositions(lineText); + return charToColumn(lineText, glyphPositions, charPos); +} + +int Document::charToColumn(const QString &lineText, const QList &glyphPositions, int charPos) const +{ + Q_ASSERT(charPos=0); + int glyphIdx; + for (glyphIdx=0;glyphIdx glyphPositions = calcGlyphPositions(lineText); + return columnToChar(lineText, glyphPositions, charPos); +} + +int Document::columnToChar(const QString &lineText, const QList &glyphPositions, int column) const +{ + } void Document::putTextStr(const QString &text) @@ -903,6 +953,38 @@ void Document::internalClear() } } +QList Document::calcGlyphColumns(const QString &lineText, const QList &glyphPositions, int colsBefore, int &totalColumns) +{ + int totalColumns = std::max(0,colsBefore); + int start,end; + QList glyphColumns; + for (int i=0;i glyphCols) { mColumns = cols; mGlyphColumns = glyphCols; } + void invalidateColumns() { mColumns = -1; mGlyphColumns.clear(); } private: QString mLineText; QList mGlyphPositions; + QList mGlyphColumns; SyntaxState mSyntaxState; int mColumns; friend class Document; @@ -87,6 +88,7 @@ public: int bracketLevel(int index); int braceLevel(int index); int lineColumns(int index); + int lineColumns(int index, const QString &newText); int blockLevel(int index); int blockStarted(int index); int blockEnded(int index); @@ -122,8 +124,13 @@ 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 glyphsColumns(const QString& lineText, const QList &glyphPositions, int colsBefore) const; + int stringColumns(const QString &lineText, int colsBefore) const; + + int charToColumn(const QString& lineText, int charPos) const; + int charToColumn(const QString& lineText, const QList &glyphPositions, int charPos) const; + int columnToChar(const QString& lineText, int column) const; + int columnToChar(const QString& lineText, const QList &glyphPositions, int column) const; + bool getAppendNewLineAtEOF(); void setAppendNewLineAtEOF(bool appendNewLineAtEOF); @@ -159,6 +166,8 @@ protected: void putTextStr(const QString& text); void internalClear(); private: + QList calcGlyphColumns(const QString& lineText, const QList &glyphPositions, int colsBefore, int &totalColumns); + int glyphsColumns(const QString& lineText, const QList &glyphPositions, int colsBefore) const; bool tryLoadFileByEncoding(QByteArray encodingName, QFile& file); void loadUTF16BOMFile(QFile& file); void loadUTF32BOMFile(QFile& file); diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index 6eadf0eb..9a06581f 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -899,9 +899,9 @@ void QSynEditPainter::paintLines() if (!edit->mSyntaxer || !edit->mSyntaxer->enabled()) { sToken = sLine; if (bCurrentLine) { - nTokenColumnLen = edit->stringColumns(sLine,0); + nTokenColumnLen = edit->lineColumns(vLine-1, sLine,0); } else { - nTokenColumnLen = edit->mDocument->lineColumns(vLine-1); + nTokenColumnLen = edit->lineColumns(vLine-1); } if (edit->mOptions.testFlag(eoShowLineBreaks) && (!bLineSelected) && (!bSpecialLine) && (nTokenColumnLen < vLastChar)) { sToken = sToken + LineBreakGlyph; diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 09b04ce8..7247d461 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -329,7 +329,7 @@ int QSynEdit::maxScrollWidth() const { int maxLen = mDocument->longestLineColumns(); if (syntaxer()) - maxLen = maxLen+stringColumns(syntaxer()->foldString(""),maxLen); + maxLen += stringColumns(syntaxer()->foldString(""),maxLen); if (mOptions.testFlag(eoScrollPastEol)) return std::max(maxLen ,1); else @@ -841,22 +841,20 @@ int QSynEdit::charToColumn(int aLine, int aChar) const { if (aLine>=1 && aLine <= mDocument->count()) { QString s = getDisplayStringAtLine(aLine); - return charToColumn(s,aChar); + QString s2 = mDocument->getLine(line-1); + if (s!=s2) + return mDocument->charToColumn(s, aChar); + else { + QList glyphPositions = mDocument->getGlyphPositions(line-1); + return mDocument->charToColumn(s, glyphPositions, aChar); + } } return aChar; } int QSynEdit::charToColumn(const QString &s, int aChar) const { - int x = 0; - int len = std::min(aChar-1,s.length()); - for (int i=0;icharToColumn(s, aChar); } int QSynEdit::columnToChar(int aLine, int aColumn) const @@ -6781,7 +6779,7 @@ void QSynEdit::setBlockEnd(BufferCoord value) } else { int maxLen = mDocument->longestLineColumns(); if (syntaxer()) - maxLen = maxLen+stringColumns(syntaxer()->foldString(""),maxLen); + maxLen += stringColumns(syntaxer()->foldString(""),maxLen); value.ch = minMax(value.ch, 1, maxLen+1); } if (value.ch != mBlockEnd.ch || value.line != mBlockEnd.line) { @@ -6888,7 +6886,7 @@ void QSynEdit::setBlockBegin(BufferCoord value) } else { int maxLen = mDocument->longestLineColumns(); if (syntaxer()) - maxLen = maxLen+stringColumns(syntaxer()->foldString(""),maxLen); + maxLen += stringColumns(syntaxer()->foldString(""),maxLen); value.ch = minMax(value.ch, 1, maxLen+1); } if (selAvail()) {