diff --git a/src/libs/cplusplus/SimpleLexer.cpp b/src/libs/cplusplus/SimpleLexer.cpp index e03208f2f7260d0e76e29876330dc29ebac50880..4db184ca1210bab7cf4c51ccbff0096b06d69506 100644 --- a/src/libs/cplusplus/SimpleLexer.cpp +++ b/src/libs/cplusplus/SimpleLexer.cpp @@ -161,7 +161,7 @@ int SimpleLexer::tokenBefore(const QList<Token> &tokens, unsigned offset) { for (int index = tokens.size() - 1; index >= 0; --index) { const Token &tk = tokens.at(index); - if (tk.begin() <= offset) + if (tk.begin() < offset) return index; } diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index f4794d4886db7b2d5b7ec198b9bb6e8547da642a..733671fa51507155aaaf152adef324cbc51f471c 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -554,9 +554,10 @@ static int startOfOperator(TextEditor::ITextEditable *editor, SimpleLexer tokenize; tokenize.setQtMocRunEnabled(true); + tokenize.setObjCEnabled(true); tokenize.setSkipComments(false); - const QList<Token> &tokens = tokenize(tc.block().text()); - const int tokenIdx = SimpleLexer::tokenAt(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor + const QList<Token> &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block())); + const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor const Token tk = (tokenIdx == -1) ? Token() : tokens.at(tokenIdx); if (completionKind == T_DOXY_COMMENT && !(tk.is(T_DOXY_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))) {