diff options
author | mae <qt-info@nokia.com> | 2010-05-26 19:18:38 +0200 |
---|---|---|
committer | hjk <qtc-committer@nokia.com> | 2010-06-07 12:36:20 +0200 |
commit | 7f7a52bac73528e1d332b2014b9d7bfef0aec29b (patch) | |
tree | da19e4ca352d0525467e13376c4fe3dba39a5cb0 | |
parent | 4dbf19681ac6c92234bc078d07a55d616f6af40c (diff) | |
download | qt-creator-7f7a52bac73528e1d332b2014b9d7bfef0aec29b.tar.gz |
Fix qml autocompletion on Enter
Only insert necessary newlines
Reviewed-by: thorbjorn
Task-number: QTCREATORBUG-1476
(cherry picked from commit 7c82944750f22dd8048177287cf3cb36e5e015d4)
-rw-r--r-- | src/plugins/qmljseditor/qmljseditor.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index b0c000cbcf..0348812557 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -1225,9 +1225,33 @@ QString QmlJSTextEditor::insertMatchingBrace(const QTextCursor &tc, const QStrin return QString(); } -QString QmlJSTextEditor::insertParagraphSeparator(const QTextCursor &) const +static bool shouldInsertNewline(const QTextCursor &tc) { - return QLatin1String("}\n"); + QTextDocument *doc = tc.document(); + int pos = tc.selectionEnd(); + + // count the number of empty lines. + int newlines = 0; + for (int e = doc->characterCount(); pos != e; ++pos) { + const QChar ch = doc->characterAt(pos); + + if (! ch.isSpace()) + break; + else if (ch == QChar::ParagraphSeparator) + ++newlines; + } + + if (newlines <= 1 && doc->characterAt(pos) != QLatin1Char('}')) + return true; + + return false; +} + +QString QmlJSTextEditor::insertParagraphSeparator(const QTextCursor &tc) const +{ + if (shouldInsertNewline(tc)) + return QLatin1String("}\n"); + return QLatin1String("}"); } void QmlJSTextEditor::forceSemanticRehighlight() |