QmlJsEditor: unify behavior of autocompletion to C++ editor.

Changed behavior of autocompletion for uniformity with C++ completion.
E.g: changing 'x' to 'c' in "Rextangle" used to trigger completion,
resulting in: "Rectangletangle".

Task-number: QTCREATORBUG-15379
Change-Id: I0597a8d76843b8f1c20c39877267aa70a6b0e1a2
Reviewed-by: Robert Loehning <robert.loehning@theqtcompany.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
Marco Benelli
2015-11-23 15:40:35 +01:00
parent aa6fb0da41
commit 466fa9636e
3 changed files with 13 additions and 0 deletions

View File

@@ -858,6 +858,8 @@ bool QmlJSCompletionAssistProcessor::acceptsIdleEditor() const
maybeAccept = true; maybeAccept = true;
} else { } else {
const QChar &charUnderCursor = m_interface->textDocument()->characterAt(cursorPos); const QChar &charUnderCursor = m_interface->textDocument()->characterAt(cursorPos);
if (isValidIdentifierChar(charUnderCursor))
return false;
if (isIdentifierChar(charBeforeCursor) if (isIdentifierChar(charBeforeCursor)
&& ((charUnderCursor.isSpace() && ((charUnderCursor.isSpace()
|| charUnderCursor.isNull() || charUnderCursor.isNull()

View File

@@ -54,6 +54,15 @@ bool isIdentifierChar(const QChar &c, bool atStart, bool acceptDollar)
} }
} }
bool isValidFirstIdentifierChar(const QChar &ch) {
return ch.isLetter() || ch == QLatin1Char('_') || ch.isHighSurrogate()
|| ch.isLowSurrogate();
}
bool isValidIdentifierChar(const QChar &ch) {
return isValidFirstIdentifierChar(ch) || ch.isNumber();
}
bool isDelimiterChar(const QChar &c) bool isDelimiterChar(const QChar &c)
{ {
switch (c.unicode()) { switch (c.unicode()) {

View File

@@ -42,6 +42,8 @@ namespace QmlJSEditor {
namespace Internal { namespace Internal {
bool isIdentifierChar(const QChar &c, bool atStart = false, bool acceptDollar = true); bool isIdentifierChar(const QChar &c, bool atStart = false, bool acceptDollar = true);
bool isValidFirstIdentifierChar(const QChar &c);
bool isValidIdentifierChar(const QChar &c);
bool isDelimiterChar(const QChar &c); bool isDelimiterChar(const QChar &c);
bool isActivationChar(const QChar &c); bool isActivationChar(const QChar &c);