Simplified triggerCompletion().

This commit is contained in:
Roberto Raggi
2010-02-01 11:40:29 +01:00
parent 18e0777e41
commit cd9d13acac

View File

@@ -519,15 +519,20 @@ static bool isIdentifierChar(QChar ch)
bool QmlCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor) bool QmlCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
{ {
const QChar ch = editor->characterAt(editor->position() - 1); const int cursorPosition = editor->position();
const QChar ch = editor->characterAt(cursorPosition - 1);
if (ch == QLatin1Char('(') || ch == QLatin1Char('.')) if (ch == QLatin1Char('(') || ch == QLatin1Char('.'))
return true; return true;
else if (isIdentifierChar(ch)) { else if (isIdentifierChar(ch)) {
if (QmlJSTextEditor *ed = qobject_cast<QmlJSTextEditor *>(editor->widget())) { int pos = editor->position() - 1;
QTextCursor tc = ed->textCursor(); for (; pos != -1; --pos) {
tc.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor); if (! isIdentifierChar(editor->characterAt(pos)))
const QString word = tc.selectedText(); break;
}
++pos;
const QString word = editor->textAt(pos, cursorPosition - pos);
if (word.length() > 2 && checkStartOfIdentifier(word)) { if (word.length() > 2 && checkStartOfIdentifier(word)) {
for (int i = 0; i < word.length(); ++i) { for (int i = 0; i < word.length(); ++i) {
if (! isIdentifierChar(word.at(i))) if (! isIdentifierChar(word.at(i)))
@@ -536,7 +541,6 @@ bool QmlCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
return true; return true;
} }
} }
}
return false; return false;
} }