Commit 36c79d44 authored by Leandro Melo's avatar Leandro Melo
Browse files

Generic highlighter: Fix to correct storage of block states when leading...

Generic highlighter: Fix to correct storage of block states when leading context sequences are nested with persistent contexts.

This situation is represented by case 5 of testPersistentContexts from the highlighter engine unit tests.
parent b97bfaa7
......@@ -273,9 +273,9 @@ void Highlighter::changeContext(const QString &contextName,
// One or more persistent contexts were popped.
const QString &currentSequence = currentContextSequence();
if (m_persistentStates.contains(currentSequence))
setCurrentBlockState(m_persistentStates.value(currentContextSequence()));
setCurrentBlockState(m_persistentStates.value(currentSequence));
else
setCurrentBlockState(m_leadingStates.value(currentContextSequence()));
setCurrentBlockState(m_leadingStates.value(currentSequence));
}
} else {
const QSharedPointer<Context> &context = definition->context(contextName);
......@@ -285,11 +285,15 @@ void Highlighter::changeContext(const QString &contextName,
else
m_contexts.push_back(context);
if (m_contexts.back()->lineEndContext() == kStay) {
// A persistent context was pushed.
if (m_contexts.back()->lineEndContext() == kStay ||
currentBlockState() >= PersistentsStart) {
const QString &currentSequence = currentContextSequence();
mapContextSequence(currentSequence);
setCurrentBlockState(m_persistentStates.value(currentSequence));
mapLeadingSequence(currentSequence);
if (m_contexts.back()->lineEndContext() == kStay) {
// A persistent context was pushed.
mapPersistentSequence(currentSequence);
setCurrentBlockState(m_persistentStates.value(currentSequence));
}
}
}
......@@ -398,11 +402,8 @@ void Highlighter::analyseConsistencyOfWillContinueBlock(const QString &text)
}
}
void Highlighter::mapContextSequence(const QString &contextSequence)
void Highlighter::mapPersistentSequence(const QString &contextSequence)
{
if (currentBlockState() < PersistentsStart && !m_leadingStates.contains(contextSequence))
m_leadingStates.insert(contextSequence, currentBlockState());
if (!m_persistentStates.contains(contextSequence)) {
int newState = m_persistentStatesCounter;
m_persistentStates.insert(contextSequence, newState);
......@@ -411,6 +412,12 @@ void Highlighter::mapContextSequence(const QString &contextSequence)
}
}
void Highlighter::mapLeadingSequence(const QString &contextSequence)
{
if (!m_leadingStates.contains(contextSequence))
m_leadingStates.insert(contextSequence, currentBlockState());
}
void Highlighter::pushContextSequence(int state)
{
const QVector<QSharedPointer<Context> > &contexts = m_persistentContexts.value(state);
......
......@@ -100,8 +100,10 @@ private:
const bool setCurrent = true);
QString currentContextSequence() const;
void mapContextSequence(const QString &contextSequence);
void mapPersistentSequence(const QString &contextSequence);
void mapLeadingSequence(const QString &contextSequence);
void pushContextSequence(int state);
void pushDynamicContext(const QSharedPointer<Context> &baseContext);
void createWillContinueBlock();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment