forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user