From 0cc5f14f299fa498ab66e6b54d496f3f18b42e6a Mon Sep 17 00:00:00 2001 From: Christian Kamm <christian.d.kamm@nokia.com> Date: Fri, 2 Oct 2009 15:06:50 +0200 Subject: [PATCH] Make [ start a block and trigger indentation in the qml editor. Reviewed-by: erikv --- src/plugins/qmleditor/qmleditor.cpp | 10 +++++---- src/plugins/qmleditor/qmlhighlighter.cpp | 6 ++++-- src/plugins/texteditor/basetexteditor.cpp | 26 ++++++++++++++++------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/plugins/qmleditor/qmleditor.cpp b/src/plugins/qmleditor/qmleditor.cpp index 2d68189a7a3..fd627aea229 100644 --- a/src/plugins/qmleditor/qmleditor.cpp +++ b/src/plugins/qmleditor/qmleditor.cpp @@ -628,7 +628,8 @@ QString ScriptEditor::wordUnderCursor() const bool ScriptEditor::isElectricCharacter(const QChar &ch) const { - if (ch == QLatin1Char('}')) + if (ch == QLatin1Char('}') + || ch == QLatin1Char(']')) return true; return false; } @@ -637,12 +638,13 @@ void ScriptEditor::indentBlock(QTextDocument *, QTextBlock block, QChar typedCha { TextEditor::TabSettings ts = tabSettings(); - if (typedChar == QLatin1Char('}') - || ((typedChar == QChar::Null) && block.text().trimmed() == "}")) { + if (typedChar == QLatin1Char('}') || typedChar == QLatin1Char(']') + || (typedChar == QChar::Null + && (block.text().trimmed() == "}" || block.text().trimmed() == "]"))) { QTextCursor tc(block); - if (typedChar == QLatin1Char('}')) + if (typedChar == QLatin1Char('}') || typedChar == QLatin1Char(']')) tc = textCursor(); if (TextEditor::TextBlockUserData::findPreviousBlockOpenParenthesis(&tc)) { diff --git a/src/plugins/qmleditor/qmlhighlighter.cpp b/src/plugins/qmleditor/qmlhighlighter.cpp index fa9bb7ace12..521ad689af0 100644 --- a/src/plugins/qmleditor/qmlhighlighter.cpp +++ b/src/plugins/qmleditor/qmlhighlighter.cpp @@ -63,14 +63,16 @@ int QmlHighlighter::onBlockStart() void QmlHighlighter::onOpeningParenthesis(QChar parenthesis, int pos) { - if (parenthesis == QLatin1Char('{')) + if (parenthesis == QLatin1Char('{') + || parenthesis == QLatin1Char('[')) ++m_braceDepth; m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Opened, parenthesis, pos)); } void QmlHighlighter::onClosingParenthesis(QChar parenthesis, int pos) { - if (parenthesis == QLatin1Char('}')) + if (parenthesis == QLatin1Char('}') + || parenthesis == QLatin1Char(']')) --m_braceDepth; m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Closed, parenthesis, pos)); } diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index b9e77254a3b..0386cec4631 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1511,9 +1511,13 @@ int Parenthesis::closeCollapseAtPos(const Parentheses &parentheses) int depth = 0; for (int i = 0; i < parentheses.size(); ++i) { const Parenthesis &p = parentheses.at(i); - if (p.chr == QLatin1Char('{') || p.chr == QLatin1Char('+')) { + if (p.chr == QLatin1Char('{') + || p.chr == QLatin1Char('+') + || p.chr == QLatin1Char('[')) { ++depth; - } else if (p.chr == QLatin1Char('}') || p.chr == QLatin1Char('-')) { + } else if (p.chr == QLatin1Char('}') + || p.chr == QLatin1Char('-') + || p.chr == QLatin1Char(']')) { if (--depth < 0) return p.pos; } @@ -1529,13 +1533,17 @@ int Parenthesis::collapseAtPos(const Parentheses &parentheses, QChar *character) int depth = 0; for (int i = 0; i < parentheses.size(); ++i) { const Parenthesis &p = parentheses.at(i); - if (p.chr == QLatin1Char('{') || p.chr == QLatin1Char('+')) { + if (p.chr == QLatin1Char('{') + || p.chr == QLatin1Char('+') + || p.chr == QLatin1Char('[')) { if (depth == 0) { result = p.pos; c = p.chr; } ++depth; - } else if (p.chr == QLatin1Char('}') || p.chr == QLatin1Char('-')) { + } else if (p.chr == QLatin1Char('}') + || p.chr == QLatin1Char('-') + || p.chr == QLatin1Char(']')) { if (--depth < 0) depth = 0; result = -1; @@ -1557,8 +1565,8 @@ int TextBlockUserData::braceDepthDelta() const int delta = 0; for (int i = 0; i < m_parentheses.size(); ++i) { switch (m_parentheses.at(i).chr.unicode()) { - case '{': case '+': ++delta; break; - case '}': case '-': --delta; break; + case '{': case '+': case '[': ++delta; break; + case '}': case '-': case ']': --delta; break; default: break; } } @@ -3676,7 +3684,8 @@ bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor, bo for (int i = parenList.count()-1; i >= 0; --i) { Parenthesis paren = parenList.at(i); if (paren.chr != QLatin1Char('{') && paren.chr != QLatin1Char('}') - && paren.chr != QLatin1Char('+') && paren.chr != QLatin1Char('-')) + && paren.chr != QLatin1Char('+') && paren.chr != QLatin1Char('-') + && paren.chr != QLatin1Char('[') && paren.chr != QLatin1Char(']')) continue; if (block == cursor->block()) { if (position - block.position() <= paren.pos + (paren.type == Parenthesis::Closed ? 1 : 0)) @@ -3739,7 +3748,8 @@ bool TextBlockUserData::findNextBlockClosingParenthesis(QTextCursor *cursor) for (int i = 0; i < parenList.count(); ++i) { Parenthesis paren = parenList.at(i); if (paren.chr != QLatin1Char('{') && paren.chr != QLatin1Char('}') - && paren.chr != QLatin1Char('+') && paren.chr != QLatin1Char('-')) + && paren.chr != QLatin1Char('+') && paren.chr != QLatin1Char('-') + && paren.chr != QLatin1Char('[') && paren.chr != QLatin1Char(']')) continue; if (block == cursor->block() && (position - block.position() > paren.pos - (paren.type == Parenthesis::Opened ? 1 : 0))) -- GitLab