forked from qt-creator/qt-creator
GlslEditor: Fix crash in GlslHighlighter
since the async highlighter implementation the parent is not a TextDocument anymore, but a QTextDocument. Pass the required mimeType via the SyntaxHighlighterRunner now to the SyntaxHighlighter. Change-Id: I0afcbe68719195649b4b7040416a743cb01214df Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
This commit is contained in:
@@ -47,10 +47,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
|
|||||||
lex.setState(state);
|
lex.setState(state);
|
||||||
lex.setScanKeywords(false);
|
lex.setScanKeywords(false);
|
||||||
lex.setScanComments(true);
|
lex.setScanComments(true);
|
||||||
const int variant = languageVariant(parent()
|
lex.setVariant(languageVariant(mimeType()));
|
||||||
? static_cast<TextDocument*>(parent())->mimeType()
|
|
||||||
: QString());
|
|
||||||
lex.setVariant(variant);
|
|
||||||
|
|
||||||
int initialState = state;
|
int initialState = state;
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@ public:
|
|||||||
QList<std::pair<int,TextStyle>> formatCategories;
|
QList<std::pair<int,TextStyle>> formatCategories;
|
||||||
QTextCharFormat whitespaceFormat;
|
QTextCharFormat whitespaceFormat;
|
||||||
bool noAutomaticHighlighting = false;
|
bool noAutomaticHighlighting = false;
|
||||||
|
QString mimeType;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsDelta)
|
static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsDelta)
|
||||||
@@ -364,6 +365,18 @@ QTextDocument *SyntaxHighlighter::document() const
|
|||||||
return d->doc;
|
return d->doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SyntaxHighlighter::setMimeType(const QString &mimeType)
|
||||||
|
{
|
||||||
|
Q_D(SyntaxHighlighter);
|
||||||
|
d->mimeType = mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SyntaxHighlighter::mimeType() const
|
||||||
|
{
|
||||||
|
Q_D(const SyntaxHighlighter);
|
||||||
|
return d->mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\since 4.2
|
\since 4.2
|
||||||
|
|
||||||
|
@@ -44,6 +44,9 @@ public:
|
|||||||
void setDocument(QTextDocument *doc);
|
void setDocument(QTextDocument *doc);
|
||||||
QTextDocument *document() const;
|
QTextDocument *document() const;
|
||||||
|
|
||||||
|
void setMimeType(const QString &mimeType);
|
||||||
|
QString mimeType() const;
|
||||||
|
|
||||||
static QList<QColor> generateColors(int n, const QColor &background);
|
static QList<QColor> generateColors(int n, const QColor &background);
|
||||||
|
|
||||||
// Don't call in constructors of derived classes
|
// Don't call in constructors of derived classes
|
||||||
|
@@ -30,6 +30,7 @@ public:
|
|||||||
SyntaxHighlighterRunnerPrivate(SyntaxHighlighterRunner::SyntaxHighlighterCreator creator,
|
SyntaxHighlighterRunnerPrivate(SyntaxHighlighterRunner::SyntaxHighlighterCreator creator,
|
||||||
QTextDocument *document,
|
QTextDocument *document,
|
||||||
bool async,
|
bool async,
|
||||||
|
const QString &mimeType,
|
||||||
FontSettings fontSettings)
|
FontSettings fontSettings)
|
||||||
{
|
{
|
||||||
if (async) {
|
if (async) {
|
||||||
@@ -42,6 +43,7 @@ public:
|
|||||||
m_highlighter.reset(creator());
|
m_highlighter.reset(creator());
|
||||||
m_highlighter->setFontSettings(fontSettings);
|
m_highlighter->setFontSettings(fontSettings);
|
||||||
m_highlighter->setDocument(m_document);
|
m_highlighter->setDocument(m_document);
|
||||||
|
m_highlighter->setMimeType(mimeType);
|
||||||
m_highlighter->setParent(m_document);
|
m_highlighter->setParent(m_document);
|
||||||
|
|
||||||
connect(m_highlighter.get(),
|
connect(m_highlighter.get(),
|
||||||
@@ -111,8 +113,9 @@ signals:
|
|||||||
SyntaxHighlighterRunner::SyntaxHighlighterRunner(SyntaxHighlighterCreator creator,
|
SyntaxHighlighterRunner::SyntaxHighlighterRunner(SyntaxHighlighterCreator creator,
|
||||||
QTextDocument *document,
|
QTextDocument *document,
|
||||||
bool async,
|
bool async,
|
||||||
|
const QString &mimeType,
|
||||||
const TextEditor::FontSettings &fontSettings)
|
const TextEditor::FontSettings &fontSettings)
|
||||||
: d(new SyntaxHighlighterRunnerPrivate(creator, document, async, fontSettings))
|
: d(new SyntaxHighlighterRunnerPrivate(creator, document, async, mimeType, fontSettings))
|
||||||
, m_document(document)
|
, m_document(document)
|
||||||
{
|
{
|
||||||
m_useGenericHighlighter = qobject_cast<Highlighter *>(d->m_highlighter.get());
|
m_useGenericHighlighter = qobject_cast<Highlighter *>(d->m_highlighter.get());
|
||||||
|
@@ -24,11 +24,12 @@ class TEXTEDITOR_EXPORT SyntaxHighlighterRunner : public QObject
|
|||||||
public:
|
public:
|
||||||
using SyntaxHighlighterCreator = std::function<SyntaxHighlighter *()>;
|
using SyntaxHighlighterCreator = std::function<SyntaxHighlighter *()>;
|
||||||
|
|
||||||
SyntaxHighlighterRunner(SyntaxHighlighterCreator creator,
|
SyntaxHighlighterRunner(
|
||||||
QTextDocument *document,
|
SyntaxHighlighterCreator creator,
|
||||||
bool async,
|
QTextDocument *document,
|
||||||
const TextEditor::FontSettings &fontSettings
|
bool async,
|
||||||
= TextEditorSettings::fontSettings());
|
const QString &mimeType,
|
||||||
|
const TextEditor::FontSettings &fontSettings = TextEditorSettings::fontSettings());
|
||||||
virtual ~SyntaxHighlighterRunner();
|
virtual ~SyntaxHighlighterRunner();
|
||||||
|
|
||||||
void setExtraFormats(const QMap<int, QList<QTextLayout::FormatRange>> &formats);
|
void setExtraFormats(const QMap<int, QList<QTextLayout::FormatRange>> &formats);
|
||||||
|
@@ -921,7 +921,10 @@ void TextDocument::resetSyntaxHighlighter(const std::function<SyntaxHighlighter
|
|||||||
= qtcEnvironmentVariable("QTC_USE_THREADED_HIGHLIGHTER", "TRUE").toUpper()
|
= qtcEnvironmentVariable("QTC_USE_THREADED_HIGHLIGHTER", "TRUE").toUpper()
|
||||||
== QLatin1String("TRUE");
|
== QLatin1String("TRUE");
|
||||||
|
|
||||||
d->m_highlighterRunner = new SyntaxHighlighterRunner(creator, document(), threaded && envValue);
|
d->m_highlighterRunner = new SyntaxHighlighterRunner(creator,
|
||||||
|
document(),
|
||||||
|
threaded && envValue,
|
||||||
|
mimeType());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextDocument::cleanWhitespace(const QTextCursor &cursor)
|
void TextDocument::cleanWhitespace(const QTextCursor &cursor)
|
||||||
|
@@ -60,7 +60,7 @@ Last)";
|
|||||||
doc->setPlainText(text);
|
doc->setPlainText(text);
|
||||||
|
|
||||||
highlighterRunner = new SyntaxHighlighterRunner(
|
highlighterRunner = new SyntaxHighlighterRunner(
|
||||||
[this] { return new SyntaxHighlighter(doc, fontsettings); }, doc, false, fontsettings);
|
[this] { return new SyntaxHighlighter(doc, fontsettings); }, doc, false, {}, fontsettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const HighlightingResults &highlightingResults()
|
static const HighlightingResults &highlightingResults()
|
||||||
|
Reference in New Issue
Block a user