Commit 40890127 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

GenericHighligher: Preserve whole context on LineContinue

Task-number: QTCREATORBUG-11063
Change-Id: I5f23a2a1f1db370e732c1a101a6581fa5c493085
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent ddab3354
......@@ -53,12 +53,17 @@ namespace {
class HighlighterCodeFormatterData : public CodeFormatterData
{
public:
HighlighterCodeFormatterData() : m_foldingIndentDelta(0), m_originalObservableState(-1) {}
HighlighterCodeFormatterData() :
m_foldingIndentDelta(0),
m_originalObservableState(-1),
m_continueObservableState(-1)
{}
~HighlighterCodeFormatterData() {}
int m_foldingIndentDelta;
int m_originalObservableState;
QStack<QString> m_foldingRegions;
QSharedPointer<Internal::Context> m_contextToContinue;
int m_continueObservableState;
};
HighlighterCodeFormatterData *formatterData(const QTextBlock &block)
......@@ -163,9 +168,11 @@ void Highlighter::highlightBlock(const QString &text)
while (progress.offset() < length)
iterateThroughRules(text, length, &progress, false, m_currentContext->rules());
handleContextChange(m_currentContext->lineEndContext(),
m_currentContext->definition(),
false);
if (extractObservableState(currentBlockState()) != WillContinue) {
handleContextChange(m_currentContext->lineEndContext(),
m_currentContext->definition(),
false);
}
m_contexts.clear();
if (m_indentationBasedFolding) {
......@@ -221,12 +228,7 @@ void Highlighter::setupDefault()
void Highlighter::setupFromWillContinue()
{
HighlighterCodeFormatterData *previousData = formatterData(currentBlock().previous());
if (previousData->m_originalObservableState == Default ||
previousData->m_originalObservableState == -1) {
m_contexts.push_back(previousData->m_contextToContinue);
} else {
pushContextSequence(previousData->m_originalObservableState);
}
pushContextSequence(previousData->m_continueObservableState);
HighlighterCodeFormatterData *data = formatterData(currentBlock());
data->m_originalObservableState = previousData->m_originalObservableState;
......@@ -466,7 +468,10 @@ void Highlighter::createWillContinueBlock()
} else if (currentObservableState != WillContinue) {
data->m_originalObservableState = currentObservableState;
}
data->m_contextToContinue = m_currentContext;
const QString currentSequence = currentContextSequence();
mapPersistentSequence(currentSequence);
data->m_continueObservableState = m_persistentObservableStates.value(currentSequence);
m_persistentContexts.insert(data->m_continueObservableState, m_contexts);
setCurrentBlockState(computeState(WillContinue));
}
......@@ -481,7 +486,6 @@ void Highlighter::analyseConsistencyOfWillContinueBlock(const QString &text)
if (text.length() == 0 || text.at(text.length() - 1) != kBackSlash) {
HighlighterCodeFormatterData *data = formatterData(currentBlock());
data->m_contextToContinue.clear();
setCurrentBlockState(computeState(data->m_originalObservableState));
}
}
......
......@@ -187,6 +187,13 @@ void tst_HighlighterEngine::createContexts()
nestedComment->setLineEndContext("#stay");
nestedComment->setDefinition(m_definition);
// SimpleNestedComment context
QSharedPointer<Context> simpleNestedComment =
m_definition->createContext("SimpleNestedComment", false);
simpleNestedComment->setItemData("Comment");
simpleNestedComment->setLineEndContext("#pop");
simpleNestedComment->setDefinition(m_definition);
// Dummy context
QSharedPointer<Context> dummy = m_definition->createContext("Dummy", false);
dummy->setItemData("Dummy");
......@@ -433,6 +440,22 @@ void tst_HighlighterEngine::createContexts()
r27->setFirstNonSpace("true");
r27->setDefinition(m_definition);
normal->addRule(QSharedPointer<Rule>(r27));
Detect2CharsRule *r28 = new Detect2CharsRule;
r28->setChar("#");
r28->setChar1("#");
r28->setItemData("Comment");
r28->setContext("SimpleNestedComment");
r28->setDefinition(m_definition);
QSharedPointer<Rule> sr28(r28);
multiComment->addRule(sr28);
nestedComment->addRule(sr28);
LineContinueRule *r29 = new LineContinueRule;
r29->setItemData("Comment");
r29->setContext("#stay");
r29->setDefinition(m_definition);
simpleNestedComment->addRule(QSharedPointer<Rule>(r29));
}
void tst_HighlighterEngine::createItemDatas()
......@@ -699,6 +722,12 @@ void tst_HighlighterEngine::testLineContinue_data()
seqe.add(3, 8);
seqe.add(8, 9, Formats::instance().baseNFormat());
seqe.add(9, 10);
HighlightSequence seqf(0, 9, Formats::instance().commentFormat());
seqf.add(9, 18, Formats::instance().errorFormat());
HighlightSequence seqg(0, 7, Formats::instance().commentFormat());
HighlightSequence seqh(0, 5, Formats::instance().commentFormat());
HighlightSequence seqi(0, 5, Formats::instance().errorFormat());
seqi.add(5, 8, Formats::instance().commentFormat());
states << 1 << 2;
sequences << seqa << seqb;
......@@ -722,6 +751,12 @@ void tst_HighlighterEngine::testLineContinue_data()
sequences << seqa << seqc << seqd << seqe;
lines = "#define max\\\n 100\\\n000\nint i = 0;";
QTest::newRow("case 3") << states << sequences << lines;
clear(&states, &sequences);
states << 4 << 1 << 1 << 2 << 3 << 0 << 1;
sequences << seqf << seqg << seqh << seqh << seqi << seqh;
lines = "/*int i; /# int j;\n##foo \\\nbar \\\nbaz \nxxx#/yyy\nzzz*/";
QTest::newRow("case 4") << states << sequences << lines;
}
void tst_HighlighterEngine::setupForEditingLineContinue()
......
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