TextEditors: Avoid multiple highlighting runs when changing font setting

And remove some unnecessary code in Python editor

Change-Id: I86cde74c244a16d1b36b0ac0e841ef8110ba832f
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-01-22 15:36:06 +01:00
parent c99464dd9b
commit 0ec2a02fd4
7 changed files with 44 additions and 35 deletions

View File

@@ -1534,11 +1534,6 @@ TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider()
void CPPEditorWidget::applyFontSettings()
{
TextEditor::BaseTextEditorWidget::applyFontSettings();
TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter();
if (!highlighter)
return;
const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings();
m_semanticHighlightFormatMap[CppHighlightingSupport::TypeUse] =
@@ -1562,16 +1557,8 @@ void CPPEditorWidget::applyFontSettings()
m_semanticHighlightFormatMap[CppHighlightingSupport::StringUse] =
fs.toTextCharFormat(TextEditor::C_STRING);
// Clear all additional formats since they may have changed
QTextBlock b = document()->firstBlock();
while (b.isValid()) {
QList<QTextLayout::FormatRange> noFormats;
highlighter->setExtraAdditionalFormats(b, noFormats);
b = b.next();
}
// This also triggers an update of the additional formats
highlighter->rehighlight();
// this also makes the document apply font settings
TextEditor::BaseTextEditorWidget::applyFontSettings();
}
void CPPEditorWidget::unCommentSelection()
@@ -2016,6 +2003,20 @@ CPPEditorDocument::CPPEditorDocument()
this, SLOT(invalidateFormatterCache()));
}
void CPPEditorDocument::applyFontSettings()
{
if (TextEditor::SyntaxHighlighter *highlighter = syntaxHighlighter()) {
// Clear all additional formats since they may have changed
QTextBlock b = document()->firstBlock();
while (b.isValid()) {
QList<QTextLayout::FormatRange> noFormats;
highlighter->setExtraAdditionalFormats(b, noFormats);
b = b.next();
}
}
BaseTextDocument::applyFontSettings(); // rehighlights and updates additional formats
}
void CPPEditorDocument::invalidateFormatterCache()
{
CppTools::QtStyleCodeFormatter formatter;