summaryrefslogtreecommitdiff
path: root/src/plugins/qtscripteditor/qtscripteditor.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-01-12 15:59:22 +0100
committerRoberto Raggi <roberto.raggi@nokia.com>2010-01-12 16:00:39 +0100
commit547912af2a282148f835abe3ccbe3e8ba9acc329 (patch)
tree035882c52b4d061953031e11fa06ea96990f6d2e /src/plugins/qtscripteditor/qtscripteditor.cpp
parente3188417c3c2cb7bf0daf18182097f7108820151 (diff)
downloadqt-creator-547912af2a282148f835abe3ccbe3e8ba9acc329.tar.gz
Speed up contextAllowsAutoParentheses().
Look at the token under cursor only if the current character is a brace or a quote.
Diffstat (limited to 'src/plugins/qtscripteditor/qtscripteditor.cpp')
-rw-r--r--src/plugins/qtscripteditor/qtscripteditor.cpp58
1 files changed, 34 insertions, 24 deletions
diff --git a/src/plugins/qtscripteditor/qtscripteditor.cpp b/src/plugins/qtscripteditor/qtscripteditor.cpp
index 6d235b5f0a..670c5c747e 100644
--- a/src/plugins/qtscripteditor/qtscripteditor.cpp
+++ b/src/plugins/qtscripteditor/qtscripteditor.cpp
@@ -409,8 +409,34 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
if (! textToInsert.isEmpty())
ch = textToInsert.at(0);
+ switch (ch.unicode()) {
+ case '\'':
+ case '"':
+
+ case '(':
+ case '[':
+ case '{':
+
+ case ')':
+ case ']':
+ case '}':
+
+ case ';':
+ break;
+
+ default:
+ if (ch.isNull())
+ break;
+
+ return false;
+ } // end of switch
+
const QString blockText = cursor.block().text();
- const int blockState = cursor.block().userState() & 0xFF;
+ int blockState = cursor.block().userState();
+ if (blockState == -1)
+ blockState = 0;
+ else
+ blockState = blockState & 0xFF;
QScriptIncrementalScanner tokenize;
const QList<QScriptIncrementalScanner::Token> tokens = tokenize(blockText, blockState);
@@ -419,8 +445,12 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
int tokenIndex = tokens.size() - 1;
for (; tokenIndex != -1; --tokenIndex) {
const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex);
- if (pos >= token.begin() && pos <= token.end())
- break;
+ if (pos >= token.begin()) {
+ if (pos < token.end())
+ break;
+ else if (pos == token.end() && token.is(QScriptIncrementalScanner::Token::Comment))
+ break;
+ }
}
if (tokenIndex != -1) {
@@ -443,27 +473,7 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
} // end of switch
}
- switch (ch.unicode()) {
- case '\'':
- case '"':
-
- case '(':
- case '[':
- case '{':
-
- case ')':
- case ']':
- case '}':
-
- case ';':
- return true;
-
- default:
- if (ch.isNull())
- return true;
- } // end of switch
-
- return false;
+ return true;
}
bool ScriptEditor::isInComment(const QTextCursor &) const