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()
|
void CPPEditorWidget::applyFontSettings()
|
||||||
{
|
{
|
||||||
TextEditor::BaseTextEditorWidget::applyFontSettings();
|
|
||||||
TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter();
|
|
||||||
if (!highlighter)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings();
|
const TextEditor::FontSettings &fs = baseTextDocument()->fontSettings();
|
||||||
|
|
||||||
m_semanticHighlightFormatMap[CppHighlightingSupport::TypeUse] =
|
m_semanticHighlightFormatMap[CppHighlightingSupport::TypeUse] =
|
||||||
@@ -1562,16 +1557,8 @@ void CPPEditorWidget::applyFontSettings()
|
|||||||
m_semanticHighlightFormatMap[CppHighlightingSupport::StringUse] =
|
m_semanticHighlightFormatMap[CppHighlightingSupport::StringUse] =
|
||||||
fs.toTextCharFormat(TextEditor::C_STRING);
|
fs.toTextCharFormat(TextEditor::C_STRING);
|
||||||
|
|
||||||
// Clear all additional formats since they may have changed
|
// this also makes the document apply font settings
|
||||||
QTextBlock b = document()->firstBlock();
|
TextEditor::BaseTextEditorWidget::applyFontSettings();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPEditorWidget::unCommentSelection()
|
void CPPEditorWidget::unCommentSelection()
|
||||||
@@ -2016,6 +2003,20 @@ CPPEditorDocument::CPPEditorDocument()
|
|||||||
this, SLOT(invalidateFormatterCache()));
|
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()
|
void CPPEditorDocument::invalidateFormatterCache()
|
||||||
{
|
{
|
||||||
CppTools::QtStyleCodeFormatter formatter;
|
CppTools::QtStyleCodeFormatter formatter;
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ class CPPEditorDocument : public TextEditor::BaseTextDocument
|
|||||||
public:
|
public:
|
||||||
CPPEditorDocument();
|
CPPEditorDocument();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void applyFontSettings();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void invalidateFormatterCache();
|
void invalidateFormatterCache();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -85,20 +85,6 @@ void EditorWidget::unCommentSelection()
|
|||||||
Utils::unCommentSelection(this, m_commentDefinition);
|
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()
|
TextEditor::BaseTextEditor *EditorWidget::createEditor()
|
||||||
{
|
{
|
||||||
return new PythonEditor(this);
|
return new PythonEditor(this);
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public:
|
|||||||
virtual void unCommentSelection();
|
virtual void unCommentSelection();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void applyFontSettings();
|
|
||||||
TextEditor::BaseTextEditor *createEditor();
|
TextEditor::BaseTextEditor *createEditor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public:
|
|||||||
TabSettings m_tabSettings;
|
TabSettings m_tabSettings;
|
||||||
ExtraEncodingSettings m_extraEncodingSettings;
|
ExtraEncodingSettings m_extraEncodingSettings;
|
||||||
FontSettings m_fontSettings;
|
FontSettings m_fontSettings;
|
||||||
|
bool m_fontSettingsNeedsApply; // for applying font settings delayed till an editor becomes visible
|
||||||
QTextDocument *m_document;
|
QTextDocument *m_document;
|
||||||
SyntaxHighlighter *m_highlighter;
|
SyntaxHighlighter *m_highlighter;
|
||||||
QScopedPointer<Indenter> m_indenter;
|
QScopedPointer<Indenter> m_indenter;
|
||||||
@@ -88,6 +89,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) :
|
BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) :
|
||||||
|
m_fontSettingsNeedsApply(false),
|
||||||
m_document(new QTextDocument(q)),
|
m_document(new QTextDocument(q)),
|
||||||
m_highlighter(0),
|
m_highlighter(0),
|
||||||
m_indenter(new Indenter),
|
m_indenter(new Indenter),
|
||||||
@@ -237,9 +239,26 @@ void BaseTextDocument::setFontSettings(const FontSettings &fontSettings)
|
|||||||
if (fontSettings == d->m_fontSettings)
|
if (fontSettings == d->m_fontSettings)
|
||||||
return;
|
return;
|
||||||
d->m_fontSettings = fontSettings;
|
d->m_fontSettings = fontSettings;
|
||||||
|
d->m_fontSettingsNeedsApply = true;
|
||||||
emit fontSettingsChanged();
|
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
|
const FontSettings &BaseTextDocument::fontSettings() const
|
||||||
{
|
{
|
||||||
return d->m_fontSettings;
|
return d->m_fontSettings;
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ public:
|
|||||||
bool reload(QString *errorString, QTextCodec *codec);
|
bool reload(QString *errorString, QTextCodec *codec);
|
||||||
void cleanWhitespace(const QTextCursor &cursor);
|
void cleanWhitespace(const QTextCursor &cursor);
|
||||||
|
|
||||||
|
void ensureFontSettingsApplied();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
||||||
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
||||||
@@ -121,6 +123,9 @@ signals:
|
|||||||
void tabSettingsChanged();
|
void tabSettingsChanged();
|
||||||
void fontSettingsChanged();
|
void fontSettingsChanged();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
virtual void applyFontSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
|
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
|
||||||
void ensureFinalNewLine(QTextCursor &cursor);
|
void ensureFinalNewLine(QTextCursor &cursor);
|
||||||
|
|||||||
@@ -5429,11 +5429,7 @@ void BaseTextEditorWidget::applyFontSettings()
|
|||||||
slotUpdateExtraAreaWidth(); // Adjust to new font width
|
slotUpdateExtraAreaWidth(); // Adjust to new font width
|
||||||
updateCurrentLineHighlight(); // Make sure it takes the new color
|
updateCurrentLineHighlight(); // Make sure it takes the new color
|
||||||
|
|
||||||
SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter();
|
baseTextDocument()->ensureFontSettingsApplied();
|
||||||
if (highlighter) {
|
|
||||||
highlighter->setFontSettings(fs);
|
|
||||||
highlighter->rehighlight();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
||||||
|
|||||||
Reference in New Issue
Block a user