diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 6e55c6d0368..a21aba0b5a6 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -3654,6 +3654,7 @@ const DisplaySettings &BaseTextEditor::displaySettings() const void BaseTextEditor::indentOrUnindent(bool doIndent) { QTextCursor cursor = textCursor(); + maybeClearSomeExtraSelections(cursor); cursor.beginEditBlock(); int pos = cursor.position(); @@ -4076,6 +4077,7 @@ void BaseTextEditor::indentBlock(QTextDocument *, QTextBlock, QChar) void BaseTextEditor::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar) { + maybeClearSomeExtraSelections(cursor); if (cursor.hasSelection()) { QTextBlock block = doc->findBlock(cursor.selectionStart()); const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next(); @@ -4090,6 +4092,7 @@ void BaseTextEditor::indent(QTextDocument *doc, const QTextCursor &cursor, QChar void BaseTextEditor::reindent(QTextDocument *doc, const QTextCursor &cursor) { + maybeClearSomeExtraSelections(cursor); if (cursor.hasSelection()) { QTextBlock block = doc->findBlock(cursor.selectionStart()); const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next(); @@ -4622,6 +4625,26 @@ QList BaseTextEditor::extraSelections(ExtraSelectionK return d->m_extraSelections[kind]; } +void BaseTextEditor::maybeClearSomeExtraSelections(const QTextCursor &cursor) +{ + const int smallSelectionSize = 50 * 50; + if (cursor.selectionEnd() - cursor.selectionStart() < smallSelectionSize) + return; + + d->m_extraSelections[TypeSelection].clear(); + d->m_extraSelections[UndefinedSymbolSelection].clear(); + d->m_extraSelections[ObjCSelection].clear(); + d->m_extraSelections[CodeWarningsSelection].clear(); + + QList all; + for (int i = 0; i < NExtraSelectionKinds; ++i) { + if (i == CodeSemanticsSelection || i == SnippetPlaceholderSelection) + continue; + all += d->m_extraSelections[i]; + } + QPlainTextEdit::setExtraSelections(all); +} + QString BaseTextEditor::extraSelectionTooltip(int pos) const { QList all; diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 7c1ab6e6120..a2b8c72b268 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -500,6 +500,8 @@ private: void updateHighlights(); void updateCurrentLineHighlight(); + void maybeClearSomeExtraSelections(const QTextCursor &cursor); + void drawFoldingMarker(QPainter *painter, const QPalette &pal, const QRect &rect, bool expanded,