Look at the token under cursor when checking if the context allows auto parentheses.

This commit is contained in:
Roberto Raggi
2010-01-12 14:30:54 +01:00
parent 1989061231
commit 84e6cfcd52
2 changed files with 27 additions and 2 deletions

View File

@@ -721,8 +721,32 @@ void QmlTextEditor::unCommentSelection()
bool QmlTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert) const
{
if (isInComment(cursor))
return false;
const QString blockText = cursor.block().text();
const int blockState = blockStartState(cursor.block());
QScriptIncrementalScanner tokenize;
const QList<QScriptIncrementalScanner::Token> tokens = tokenize(blockText, blockState);
const int pos = cursor.columnNumber();
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 (tokenIndex != -1) {
const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex);
switch (token.kind) {
case QScriptIncrementalScanner::Token::Comment:
case QScriptIncrementalScanner::Token::String:
return false;
default:
break;
} // end of switch
}
QChar ch;

View File

@@ -65,6 +65,7 @@ public:
} kind;
inline Token(int o, int l, Kind k): offset(o), length(l), kind(k) {}
inline int begin() const { return offset; }
inline int end() const { return offset + length; }
inline bool is(int k) const { return k == kind; }
inline bool isNot(int k) const { return k != kind; }