diff --git a/src/libs/qmljs/qmljsscanner.cpp b/src/libs/qmljs/qmljsscanner.cpp index 79f81509f23ee871f62e5350aaf9be54476fd11a..9a629db9a911922eadab9ef870854ab6d20170d7 100644 --- a/src/libs/qmljs/qmljsscanner.cpp +++ b/src/libs/qmljs/qmljsscanner.cpp @@ -77,7 +77,7 @@ const _Tp *end(const _Tp (&a)[N]) } Scanner::Scanner() - : _state(0), + : _state(Normal), _scanComments(true) { } @@ -122,11 +122,6 @@ static bool isNumberChar(QChar ch) QList<Token> Scanner::operator()(const QString &text, int startState) { - enum { - Normal = 0, - MultiLineComment = 1 - }; - _state = startState; QList<Token> tokens; diff --git a/src/libs/qmljs/qmljsscanner.h b/src/libs/qmljs/qmljsscanner.h index 9141842cd71e3403ac3413f67c7b092b8eee1070..611024d426290b65e448626427a15ff014d9f96e 100644 --- a/src/libs/qmljs/qmljsscanner.h +++ b/src/libs/qmljs/qmljsscanner.h @@ -77,13 +77,18 @@ public: class QMLJS_EXPORT Scanner { public: + enum { + Normal = 0, + MultiLineComment = 1 + }; + Scanner(); virtual ~Scanner(); bool scanComments() const; void setScanComments(bool scanComments); - QList<Token> operator()(const QString &text, int startState = 0); + QList<Token> operator()(const QString &text, int startState = Normal); int state() const; bool isKeyword(const QString &text) const; diff --git a/src/plugins/qmljseditor/qmljshighlighter.cpp b/src/plugins/qmljseditor/qmljshighlighter.cpp index 685d7bb80ce667a2bc36ce039a79e7311d43f1d1..bb637fc7017d4dfc1e52e9987acac6a87685c6cc 100644 --- a/src/plugins/qmljseditor/qmljshighlighter.cpp +++ b/src/plugins/qmljseditor/qmljshighlighter.cpp @@ -40,7 +40,8 @@ using namespace QmlJS; Highlighter::Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent), - m_qmlEnabled(true) + m_qmlEnabled(true), + m_inMultilineComment(false) { m_currentBlockParentheses.reserve(20); m_braceDepth = 0; @@ -98,6 +99,13 @@ void Highlighter::highlightBlock(const QString &text) break; case Token::Comment: + if (m_inMultilineComment && text.midRef(token.end() - 2) == QLatin1String("*/")) { + onClosingParenthesis('-', token.end() - 1); + m_inMultilineComment = false; + } else if (!m_inMultilineComment && m_scanner.state() == Scanner::MultiLineComment) { + onOpeningParenthesis('+', token.offset); + m_inMultilineComment = true; + } setFormat(token.offset, token.length, m_formats[CommentFormat]); break; @@ -305,8 +313,9 @@ int Highlighter::onBlockStart() int state = 0; int previousState = previousBlockState(); if (previousState != -1) { - state = previousState & 0xff; - m_braceDepth = previousState >> 8; + m_inMultilineComment = previousState & 0x1; + state = (previousState >> 1) & 0xff; + m_braceDepth = (previousState >> 9); } return state; @@ -316,7 +325,7 @@ void Highlighter::onBlockEnd(int state, int firstNonSpace) { typedef TextEditor::TextBlockUserData TextEditorBlockData; - setCurrentBlockState((m_braceDepth << 8) | state); + setCurrentBlockState((m_braceDepth << 9) | (state << 1) | m_inMultilineComment); // Set block data parentheses. Force creation of block data unless empty TextEditorBlockData *blockData = 0; @@ -335,15 +344,22 @@ void Highlighter::onBlockEnd(int state, int firstNonSpace) } if (!m_currentBlockParentheses.isEmpty()) { QTC_ASSERT(blockData, return); - int collapse = Parenthesis::collapseAtPos(m_currentBlockParentheses); + blockData->setParentheses(m_currentBlockParentheses); + QChar c; + int collapse = Parenthesis::collapseAtPos(m_currentBlockParentheses, &c); if (collapse >= 0) { - if (collapse == firstNonSpace) + if (collapse == firstNonSpace && c != '+') blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseThis); else blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseAfter); } - if (Parenthesis::hasClosingCollapse(m_currentBlockParentheses)) - blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse); + collapse = Parenthesis::closeCollapseAtPos(m_currentBlockParentheses, &c); + if (collapse >= 0) { + if (c != '-') + blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse); + else + blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::ClosingCollapseAtEnd); + } } } diff --git a/src/plugins/qmljseditor/qmljshighlighter.h b/src/plugins/qmljseditor/qmljshighlighter.h index 974bbe9012b6f133bb0fe5b9c663320b3099f011..f33615c8a95e4b8df140235a87f0f003d309f7ee 100644 --- a/src/plugins/qmljseditor/qmljshighlighter.h +++ b/src/plugins/qmljseditor/qmljshighlighter.h @@ -94,6 +94,7 @@ private: bool m_qmlEnabled; int m_braceDepth; + bool m_inMultilineComment; QmlJS::Scanner m_scanner; Parentheses m_currentBlockParentheses; diff --git a/src/plugins/texteditor/basetextdocumentlayout.cpp b/src/plugins/texteditor/basetextdocumentlayout.cpp index 3f4c3ad541a1499137f6b43b6a5d4338efcf0526..9255f2e1a2c858f3ab6b471b078d4e5075c0d283 100644 --- a/src/plugins/texteditor/basetextdocumentlayout.cpp +++ b/src/plugins/texteditor/basetextdocumentlayout.cpp @@ -36,7 +36,7 @@ bool Parenthesis::hasClosingCollapse(const Parentheses &parentheses) return closeCollapseAtPos(parentheses) >= 0; } -int Parenthesis::closeCollapseAtPos(const Parentheses &parentheses) +int Parenthesis::closeCollapseAtPos(const Parentheses &parentheses, QChar *character) { int depth = 0; for (int i = 0; i < parentheses.size(); ++i) { @@ -48,8 +48,11 @@ int Parenthesis::closeCollapseAtPos(const Parentheses &parentheses) } else if (p.chr == QLatin1Char('}') || p.chr == QLatin1Char('-') || p.chr == QLatin1Char(']')) { - if (--depth < 0) + if (--depth < 0) { + if (character) + *character = p.chr; return p.pos; + } } } return -1; diff --git a/src/plugins/texteditor/basetextdocumentlayout.h b/src/plugins/texteditor/basetextdocumentlayout.h index c2ba64a50cdc8d570ff00ac6e08833c71084bb59..2853777ae57e5780b3bf06c32a4b26b51119f2aa 100644 --- a/src/plugins/texteditor/basetextdocumentlayout.h +++ b/src/plugins/texteditor/basetextdocumentlayout.h @@ -53,7 +53,7 @@ struct TEXTEDITOR_EXPORT Parenthesis QChar chr; int pos; static int collapseAtPos(const Parentheses &parentheses, QChar *character = 0); - static int closeCollapseAtPos(const Parentheses &parentheses); + static int closeCollapseAtPos(const Parentheses &parentheses, QChar *character = 0); static bool hasClosingCollapse(const Parentheses &parentheses); };