forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
|
||||
@@ -77,6 +77,9 @@ class CPPEditorDocument : public TextEditor::BaseTextDocument
|
||||
public:
|
||||
CPPEditorDocument();
|
||||
|
||||
protected:
|
||||
void applyFontSettings();
|
||||
|
||||
private slots:
|
||||
void invalidateFormatterCache();
|
||||
};
|
||||
|
||||
@@ -85,20 +85,6 @@ void EditorWidget::unCommentSelection()
|
||||
Utils::unCommentSelection(this, m_commentDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
Handles common IDE fonts&colors settings
|
||||
(Tools -> Options -> Text editor -> Fonts and colors)
|
||||
*/
|
||||
void EditorWidget::applyFontSettings()
|
||||
{
|
||||
TextEditor::BaseTextEditorWidget::applyFontSettings();
|
||||
|
||||
PythonHighlighter *highlighter =
|
||||
qobject_cast<PythonHighlighter *>(baseTextDocument()->syntaxHighlighter());
|
||||
if (highlighter)
|
||||
highlighter->setFontSettings(baseTextDocument()->fontSettings());
|
||||
}
|
||||
|
||||
TextEditor::BaseTextEditor *EditorWidget::createEditor()
|
||||
{
|
||||
return new PythonEditor(this);
|
||||
|
||||
@@ -48,7 +48,6 @@ public:
|
||||
virtual void unCommentSelection();
|
||||
|
||||
protected:
|
||||
void applyFontSettings();
|
||||
TextEditor::BaseTextEditor *createEditor();
|
||||
|
||||
private:
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
TabSettings m_tabSettings;
|
||||
ExtraEncodingSettings m_extraEncodingSettings;
|
||||
FontSettings m_fontSettings;
|
||||
bool m_fontSettingsNeedsApply; // for applying font settings delayed till an editor becomes visible
|
||||
QTextDocument *m_document;
|
||||
SyntaxHighlighter *m_highlighter;
|
||||
QScopedPointer<Indenter> m_indenter;
|
||||
@@ -88,6 +89,7 @@ public:
|
||||
};
|
||||
|
||||
BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) :
|
||||
m_fontSettingsNeedsApply(false),
|
||||
m_document(new QTextDocument(q)),
|
||||
m_highlighter(0),
|
||||
m_indenter(new Indenter),
|
||||
@@ -237,9 +239,26 @@ void BaseTextDocument::setFontSettings(const FontSettings &fontSettings)
|
||||
if (fontSettings == d->m_fontSettings)
|
||||
return;
|
||||
d->m_fontSettings = fontSettings;
|
||||
d->m_fontSettingsNeedsApply = true;
|
||||
emit fontSettingsChanged();
|
||||
}
|
||||
|
||||
void BaseTextDocument::ensureFontSettingsApplied()
|
||||
{
|
||||
if (!d->m_fontSettingsNeedsApply)
|
||||
return;
|
||||
d->m_fontSettingsNeedsApply = false;
|
||||
applyFontSettings();
|
||||
}
|
||||
|
||||
void BaseTextDocument::applyFontSettings()
|
||||
{
|
||||
if (d->m_highlighter) {
|
||||
d->m_highlighter->setFontSettings(d->m_fontSettings);
|
||||
d->m_highlighter->rehighlight();
|
||||
}
|
||||
}
|
||||
|
||||
const FontSettings &BaseTextDocument::fontSettings() const
|
||||
{
|
||||
return d->m_fontSettings;
|
||||
|
||||
@@ -112,6 +112,8 @@ public:
|
||||
bool reload(QString *errorString, QTextCodec *codec);
|
||||
void cleanWhitespace(const QTextCursor &cursor);
|
||||
|
||||
void ensureFontSettingsApplied();
|
||||
|
||||
public slots:
|
||||
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
||||
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
||||
@@ -121,6 +123,9 @@ signals:
|
||||
void tabSettingsChanged();
|
||||
void fontSettingsChanged();
|
||||
|
||||
protected slots:
|
||||
virtual void applyFontSettings();
|
||||
|
||||
private:
|
||||
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
|
||||
void ensureFinalNewLine(QTextCursor &cursor);
|
||||
|
||||
@@ -5429,11 +5429,7 @@ void BaseTextEditorWidget::applyFontSettings()
|
||||
slotUpdateExtraAreaWidth(); // Adjust to new font width
|
||||
updateCurrentLineHighlight(); // Make sure it takes the new color
|
||||
|
||||
SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter();
|
||||
if (highlighter) {
|
||||
highlighter->setFontSettings(fs);
|
||||
highlighter->rehighlight();
|
||||
}
|
||||
baseTextDocument()->ensureFontSettingsApplied();
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
||||
|
||||
Reference in New Issue
Block a user