diff options
author | Eike Ziller <eike.ziller@digia.com> | 2014-02-06 12:59:00 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2014-02-06 13:15:22 +0100 |
commit | 5f94bc4d12df66f9bb8a3b832f5f1aaab2ad61b7 (patch) | |
tree | eddd7ebab661d028e575760d9bf848869905ecfc /src/plugins/qmljseditor | |
parent | 99dec874062d034fbb6b58588e49cdeeace6639c (diff) |
QmlJSEditor: Move semantic highlighting to document
This ensures that we are only highlighting once, and actually do
highlight (the previous code was trying to prevent multiple rehighlights
though doing the highlighting in the editor(s), resulting in situations
where it wouldn't rehighlight at all)
Change-Id: I18f3e72e31d8076b6d1575f1a17a3f4a101163d9
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r-- | src/plugins/qmljseditor/qmljseditor.cpp | 13 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditor.h | 3 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditordocument.cpp | 26 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditordocument.h | 4 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditordocument_p.h | 3 |
5 files changed, 36 insertions, 13 deletions
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 6dd1c856b2a..2b7814d08a7 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -38,7 +38,6 @@ #include "qmljsautocompleter.h" #include "qmljscompletionassist.h" #include "qmljsquickfixassist.h" -#include "qmljssemantichighlighter.h" #include <qmljs/qmljsbind.h> #include <qmljs/qmljsevaluate.h> @@ -118,7 +117,6 @@ void QmlJSTextEditorWidget::ctor() m_outlineModel = new QmlOutlineModel(this); m_contextPane = 0; m_findReferences = new FindReferences(this); - m_semanticHighlighter = new SemanticHighlighter(m_qmlJsEditorDocument); setParenthesesMatchingEnabled(true); setMarksVisible(true); @@ -567,11 +565,8 @@ void QmlJSTextEditorWidget::setSelectedElements() void QmlJSTextEditorWidget::applyFontSettings() { TextEditor::BaseTextEditorWidget::applyFontSettings(); - m_semanticHighlighter->updateFontSettings(baseTextDocument()->fontSettings()); - if (!m_qmlJsEditorDocument->isSemanticInfoOutdated()) { - m_semanticHighlighter->rerun(m_qmlJsEditorDocument->semanticInfo()); + if (!m_qmlJsEditorDocument->isSemanticInfoOutdated()) updateUses(); - } } @@ -863,6 +858,9 @@ void QmlJSTextEditorWidget::unCommentSelection() void QmlJSTextEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo) { + if (isVisible()) + baseTextDocument()->triggerPendingUpdates(); // trigger semantic highlighting if necessary + if (m_contextPane) { Node *newNode = semanticInfo.declaringMemberNoProperties(position()); if (newNode) { @@ -875,9 +873,6 @@ void QmlJSTextEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo // update outline m_updateOutlineTimer->start(); - - if (EditorManager::currentEditor() == editor()) - m_semanticHighlighter->rerun(semanticInfo); } void QmlJSTextEditorWidget::onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index c5b6ffd9ddd..5b6c6c69776 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -71,8 +71,6 @@ class FindReferences; namespace Internal { class QmlJSEditorDocument; class QmlOutlineModel; -class SemanticHighlighter; - } // namespace Internal struct QMLJSEDITOR_EXPORT Declaration @@ -183,7 +181,6 @@ private: int m_oldCursorPosition; FindReferences *m_findReferences; - Internal::SemanticHighlighter *m_semanticHighlighter; }; } // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljseditordocument.cpp b/src/plugins/qmljseditor/qmljseditordocument.cpp index 443659f1994..8cf8e24f19f 100644 --- a/src/plugins/qmljseditor/qmljseditordocument.cpp +++ b/src/plugins/qmljseditor/qmljseditordocument.cpp @@ -31,6 +31,7 @@ #include "qmljseditordocument_p.h" #include "qmljshighlighter.h" +#include "qmljssemantichighlighter.h" #include "qmljssemanticinfoupdater.h" #include <qmljstools/qmljsindenter.h> @@ -396,7 +397,9 @@ namespace Internal { QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *parent) : m_q(parent), - m_semanticInfoDocRevision(-1) + m_semanticInfoDocRevision(-1), + m_semanticHighlighter(new SemanticHighlighter(parent)), + m_semanticHighlightingNecessary(false) { ModelManagerInterface *modelManager = ModelManagerInterface::instance(); @@ -487,6 +490,7 @@ void QmlJSEditorDocumentPrivate::acceptNewSemanticInfo(const SemanticInfo &seman FindIdDeclarations updateIds; m_semanticInfo.idLocations = updateIds(doc); + m_semanticHighlightingNecessary = true; emit m_q->semanticInfoUpdated(m_semanticInfo); } @@ -524,5 +528,25 @@ void QmlJSEditorDocument::setDiagnosticRanges(const QVector<QTextLayout::FormatR m_d->m_diagnosticRanges = ranges; } +void QmlJSEditorDocument::applyFontSettings() +{ + BaseTextDocument::applyFontSettings(); + m_d->m_semanticHighlighter->updateFontSettings(fontSettings()); + if (!isSemanticInfoOutdated()) { + m_d->m_semanticHighlightingNecessary = false; + m_d->m_semanticHighlighter->rerun(m_d->m_semanticInfo); + } +} + +void QmlJSEditorDocument::triggerPendingUpdates() +{ + BaseTextDocument::triggerPendingUpdates(); // calls applyFontSettings if necessary + // might still need to rehighlight if font settings did not change + if (m_d->m_semanticHighlightingNecessary && !isSemanticInfoOutdated()) { + m_d->m_semanticHighlightingNecessary = false; + m_d->m_semanticHighlighter->rerun(m_d->m_semanticInfo); + } +} + } // Internal } // QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljseditordocument.h b/src/plugins/qmljseditor/qmljseditordocument.h index cbd86f0d233..551256c01ce 100644 --- a/src/plugins/qmljseditor/qmljseditordocument.h +++ b/src/plugins/qmljseditor/qmljseditordocument.h @@ -57,6 +57,10 @@ signals: void updateCodeWarnings(QmlJS::Document::Ptr doc); void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo); +protected: + void applyFontSettings(); + void triggerPendingUpdates(); + private: friend class QmlJSEditorDocumentPrivate; // sending signals QmlJSEditorDocumentPrivate *m_d; diff --git a/src/plugins/qmljseditor/qmljseditordocument_p.h b/src/plugins/qmljseditor/qmljseditordocument_p.h index f96565b44ca..90df5e10afb 100644 --- a/src/plugins/qmljseditor/qmljseditordocument_p.h +++ b/src/plugins/qmljseditor/qmljseditordocument_p.h @@ -41,6 +41,7 @@ namespace QmlJSEditor { namespace Internal { class QmlJSEditorDocument; +class SemanticHighlighter; class SemanticInfoUpdater; class QmlJSEditorDocumentPrivate : public QObject @@ -66,6 +67,8 @@ public: SemanticInfoUpdater *m_semanticInfoUpdater; QmlJSTools::SemanticInfo m_semanticInfo; QVector<QTextLayout::FormatRange> m_diagnosticRanges; + Internal::SemanticHighlighter *m_semanticHighlighter; + bool m_semanticHighlightingNecessary; }; } // Internal |