diff --git a/src/buffer/katetextbuffer.cpp b/src/buffer/katetextbuffer.cpp --- a/src/buffer/katetextbuffer.cpp +++ b/src/buffer/katetextbuffer.cpp @@ -68,7 +68,7 @@ , m_generateByteOrderMark(false) , m_endOfLineMode(eolUnix) , m_newLineAtEof(false) - , m_lineLengthLimit(4096) + , m_lineLengthLimit(100000) , m_alwaysUseKAuthForSave(alwaysUseKAuth) { // minimal block size must be > 0 diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -2308,8 +2308,12 @@ QPointer message = new KTextEditor::Message(i18n("The file %1 was opened and contained lines longer than the configured Line Length Limit (%2 characters).
" "The longest of those lines was %3 characters long
" - "Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.", - this->url().toDisplayString(QUrl::PreferLocalFile), config()->lineLengthLimit(), m_buffer->longestLineLoaded()), + "Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.
" + "
Note: Highlighting for lines longer than %4 characters is disabled for performance reasons.", + this->url().toDisplayString(QUrl::PreferLocalFile), + config()->lineLengthLimit(), + m_buffer->longestLineLoaded(), + KateRenderer::maxHighlightLength()), KTextEditor::Message::Warning); QAction *increaseAndReload = new QAction(i18n("Temporarily raise limit and reload file"), message); connect(increaseAndReload, SIGNAL(triggered()), this, SLOT(openWithLineLengthLimitOverride())); @@ -2324,6 +2328,16 @@ "The longest of those lines was %3 characters long
" "Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.", this->url().toDisplayString(QUrl::PreferLocalFile), config()->lineLengthLimit(),m_buffer->longestLineLoaded()); } + // warn long lines + else if (m_buffer->longestLineLoaded() > KateRenderer::maxHighlightLength()) { + QPointer message + = new KTextEditor::Message(i18n("The file %1 contains lines longer than %2 characters.
" + "
Note: Highlighting for lines longer than %2 characters is disabled for performance reasons.", + this->url().toDisplayString(QUrl::PreferLocalFile), KateRenderer::maxHighlightLength()), KTextEditor::Message::Information); + message->setWordWrap(true); + postMessage(message); + } + // // return the success diff --git a/src/render/katerenderer.h b/src/render/katerenderer.h --- a/src/render/katerenderer.h +++ b/src/render/katerenderer.h @@ -365,6 +365,11 @@ KTextEditor::Attribute::Ptr attribute(uint pos) const; KTextEditor::Attribute::Ptr specificAttribute(int context) const; + /** + * This constant is the maximum length a line can have and still be highlighted. + */ + inline static int maxHighlightLength() { return 1024; } + private: /** * Paint a trailing space on position (x, y). diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -384,19 +384,26 @@ { QVector newHighlight; + if (textLine->length() > maxHighlightLength() && !selectionsOnly) { + return newHighlight; + } + // Don't compute the highlighting if there isn't going to be any highlighting QList rangesWithAttributes = m_doc->buffer().rangesForLine(line, m_printerFriendly ? nullptr : m_view, true); if (selectionsOnly || !textLine->attributesList().isEmpty() || !rangesWithAttributes.isEmpty()) { RenderRangeList renderRanges; - // Add the inbuilt highlighting to the list - NormalRenderRange *inbuiltHighlight = new NormalRenderRange(); - const QVector &al = textLine->attributesList(); - for (int i = 0; i < al.count(); ++i) - if (al[i].length > 0 && al[i].attributeValue > 0) { - inbuiltHighlight->addRange(new KTextEditor::Range(KTextEditor::Cursor(line, al[i].offset), al[i].length), specificAttribute(al[i].attributeValue)); + if (textLine->length() <= maxHighlightLength()) { + // Add the inbuilt highlighting to the list + NormalRenderRange *inbuiltHighlight = new NormalRenderRange(); + const QVector &al = textLine->attributesList(); + for (int i = 0; i < al.count(); ++i) { + if (al[i].length > 0 && al[i].attributeValue > 0) { + inbuiltHighlight->addRange(new KTextEditor::Range(KTextEditor::Cursor(line, al[i].offset), al[i].length), specificAttribute(al[i].attributeValue)); + } } - renderRanges.append(inbuiltHighlight); + renderRanges.append(inbuiltHighlight); + } if (!completionHighlight) { // check for dynamic hl stuff