forked from qt-creator/qt-creator
C++ editor: Drop extra selections before large editing operations.
Updating the text cursors that the extra selections are based on can get quite slow if there are changes in a lot of positions - like when reindenting a file. Dropping some text cursors can increase performance significantly in these cases. Done-with: mae
This commit is contained in:
@@ -3654,6 +3654,7 @@ const DisplaySettings &BaseTextEditor::displaySettings() const
|
|||||||
void BaseTextEditor::indentOrUnindent(bool doIndent)
|
void BaseTextEditor::indentOrUnindent(bool doIndent)
|
||||||
{
|
{
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
|
maybeClearSomeExtraSelections(cursor);
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
|
|
||||||
int pos = cursor.position();
|
int pos = cursor.position();
|
||||||
@@ -4076,6 +4077,7 @@ void BaseTextEditor::indentBlock(QTextDocument *, QTextBlock, QChar)
|
|||||||
|
|
||||||
void BaseTextEditor::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar)
|
void BaseTextEditor::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar)
|
||||||
{
|
{
|
||||||
|
maybeClearSomeExtraSelections(cursor);
|
||||||
if (cursor.hasSelection()) {
|
if (cursor.hasSelection()) {
|
||||||
QTextBlock block = doc->findBlock(cursor.selectionStart());
|
QTextBlock block = doc->findBlock(cursor.selectionStart());
|
||||||
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
|
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)
|
void BaseTextEditor::reindent(QTextDocument *doc, const QTextCursor &cursor)
|
||||||
{
|
{
|
||||||
|
maybeClearSomeExtraSelections(cursor);
|
||||||
if (cursor.hasSelection()) {
|
if (cursor.hasSelection()) {
|
||||||
QTextBlock block = doc->findBlock(cursor.selectionStart());
|
QTextBlock block = doc->findBlock(cursor.selectionStart());
|
||||||
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
|
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
|
||||||
@@ -4622,6 +4625,26 @@ QList<QTextEdit::ExtraSelection> BaseTextEditor::extraSelections(ExtraSelectionK
|
|||||||
return d->m_extraSelections[kind];
|
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<QTextEdit::ExtraSelection> 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
|
QString BaseTextEditor::extraSelectionTooltip(int pos) const
|
||||||
{
|
{
|
||||||
QList<QTextEdit::ExtraSelection> all;
|
QList<QTextEdit::ExtraSelection> all;
|
||||||
|
|||||||
@@ -500,6 +500,8 @@ private:
|
|||||||
void updateHighlights();
|
void updateHighlights();
|
||||||
void updateCurrentLineHighlight();
|
void updateCurrentLineHighlight();
|
||||||
|
|
||||||
|
void maybeClearSomeExtraSelections(const QTextCursor &cursor);
|
||||||
|
|
||||||
void drawFoldingMarker(QPainter *painter, const QPalette &pal,
|
void drawFoldingMarker(QPainter *painter, const QPalette &pal,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
bool expanded,
|
bool expanded,
|
||||||
|
|||||||
Reference in New Issue
Block a user