Commit efc0b208 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Made typing parenthesis even faster

Only attempt to activate the completion when there is a function id on
the left of the parenthesis.

Reviewed-by: Roberto Raggi
parent 39b0da2a
......@@ -56,6 +56,12 @@ public:
inline int length() const
{ return _length; }
inline int begin() const
{ return _position; }
inline int end() const
{ return _position + _length; }
inline QStringRef text() const
{ return _text; }
......
......@@ -42,7 +42,7 @@ TokenUnderCursor::TokenUnderCursor()
TokenUnderCursor::~TokenUnderCursor()
{ }
SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor, QTextBlock *b) const
SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor, QTextBlock *b)
{
SimpleLexer tokenize;
tokenize.setObjCEnabled(true);
......@@ -51,9 +51,9 @@ SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor, QTextBlock *
QTextBlock block = cursor.block();
int column = cursor.columnNumber();
QList<SimpleToken> tokens = tokenize(block.text(), previousBlockState(block));
for (int index = tokens.size() - 1; index != -1; --index) {
const SimpleToken &tk = tokens.at(index);
_tokens = tokenize(block.text(), previousBlockState(block));
for (int index = _tokens.size() - 1; index != -1; --index) {
const SimpleToken &tk = _tokens.at(index);
if (tk.position() < column) {
if (b)
*b = block;
......
......@@ -40,18 +40,21 @@ QT_END_NAMESPACE
namespace CPlusPlus {
class SimpleToken;
class CPLUSPLUS_EXPORT TokenUnderCursor
{
public:
TokenUnderCursor();
~TokenUnderCursor();
SimpleToken operator()(const QTextCursor &cursor, QTextBlock *block = 0) const;
SimpleToken operator()(const QTextCursor &cursor, QTextBlock *block = 0);
const QList<SimpleToken> &tokens() const
{ return _tokens; }
private:
int previousBlockState(const QTextBlock &block) const;
QList<SimpleToken> _tokens;
};
} // end of namespace CPlusPlus
......
......@@ -514,6 +514,26 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
start = pos;
}
if (k == T_LPAREN) {
const QList<SimpleToken> &tokens = tokenUnderCursor.tokens();
int i = 0;
for (; i < tokens.size(); ++i) {
const SimpleToken &token = tokens.at(i);
if (token.position() == tk.position()) {
if (i == 0) // no token on the left, but might be on a previous line
break;
const SimpleToken &previousToken = tokens.at(i - 1);
if (previousToken.is(T_IDENTIFIER) || previousToken.is(T_GREATER))
break;
}
}
if (i == tokens.size()) {
k = T_EOF_SYMBOL;
start = pos;
}
}
if (kind)
*kind = k;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment