forked from qt-creator/qt-creator
Speed up contextAllowsAutoParentheses().
Look at the token under cursor only if the current character is a brace or a quote.
This commit is contained in:
@@ -726,6 +726,28 @@ bool QmlTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, cons
|
|||||||
if (! textToInsert.isEmpty())
|
if (! textToInsert.isEmpty())
|
||||||
ch = textToInsert.at(0);
|
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 QString blockText = cursor.block().text();
|
||||||
const int blockState = blockStartState(cursor.block());
|
const int blockState = blockStartState(cursor.block());
|
||||||
|
|
||||||
@@ -736,8 +758,12 @@ bool QmlTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, cons
|
|||||||
int tokenIndex = tokens.size() - 1;
|
int tokenIndex = tokens.size() - 1;
|
||||||
for (; tokenIndex != -1; --tokenIndex) {
|
for (; tokenIndex != -1; --tokenIndex) {
|
||||||
const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex);
|
const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex);
|
||||||
if (pos >= token.begin() && pos <= token.end())
|
if (pos >= token.begin()) {
|
||||||
break;
|
if (pos < token.end())
|
||||||
|
break;
|
||||||
|
else if (pos == token.end() && token.is(QScriptIncrementalScanner::Token::Comment))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenIndex != -1) {
|
if (tokenIndex != -1) {
|
||||||
@@ -760,27 +786,7 @@ bool QmlTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, cons
|
|||||||
} // end of switch
|
} // end of switch
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ch.unicode()) {
|
return true;
|
||||||
case '\'':
|
|
||||||
case '"':
|
|
||||||
|
|
||||||
case '(':
|
|
||||||
case '[':
|
|
||||||
case '{':
|
|
||||||
|
|
||||||
case ')':
|
|
||||||
case ']':
|
|
||||||
case '}':
|
|
||||||
|
|
||||||
case ';':
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (ch.isNull())
|
|
||||||
return true;
|
|
||||||
} // end of switch
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlTextEditor::isInComment(const QTextCursor &) const
|
bool QmlTextEditor::isInComment(const QTextCursor &) const
|
||||||
|
|||||||
@@ -409,8 +409,34 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
|
|||||||
if (! textToInsert.isEmpty())
|
if (! textToInsert.isEmpty())
|
||||||
ch = textToInsert.at(0);
|
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 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;
|
QScriptIncrementalScanner tokenize;
|
||||||
const QList<QScriptIncrementalScanner::Token> tokens = tokenize(blockText, blockState);
|
const QList<QScriptIncrementalScanner::Token> tokens = tokenize(blockText, blockState);
|
||||||
@@ -419,8 +445,12 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
|
|||||||
int tokenIndex = tokens.size() - 1;
|
int tokenIndex = tokens.size() - 1;
|
||||||
for (; tokenIndex != -1; --tokenIndex) {
|
for (; tokenIndex != -1; --tokenIndex) {
|
||||||
const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex);
|
const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex);
|
||||||
if (pos >= token.begin() && pos <= token.end())
|
if (pos >= token.begin()) {
|
||||||
break;
|
if (pos < token.end())
|
||||||
|
break;
|
||||||
|
else if (pos == token.end() && token.is(QScriptIncrementalScanner::Token::Comment))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenIndex != -1) {
|
if (tokenIndex != -1) {
|
||||||
@@ -443,27 +473,7 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const
|
|||||||
} // end of switch
|
} // end of switch
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ch.unicode()) {
|
return true;
|
||||||
case '\'':
|
|
||||||
case '"':
|
|
||||||
|
|
||||||
case '(':
|
|
||||||
case '[':
|
|
||||||
case '{':
|
|
||||||
|
|
||||||
case ')':
|
|
||||||
case ']':
|
|
||||||
case '}':
|
|
||||||
|
|
||||||
case ';':
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (ch.isNull())
|
|
||||||
return true;
|
|
||||||
} // end of switch
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptEditor::isInComment(const QTextCursor &) const
|
bool ScriptEditor::isInComment(const QTextCursor &) const
|
||||||
|
|||||||
Reference in New Issue
Block a user