From 395ba9875a4fb85757fdf104362984d01f7af0a2 Mon Sep 17 00:00:00 2001
From: Leandro Melo <leandro.melo@nokia.com>
Date: Thu, 23 Jun 2011 15:35:07 +0200
Subject: [PATCH] CodeAssist: Relax a bit premature match

In a relatively recent commit (99fee33fd1a5e82b7be3d17a74229efaaf7571ef)
premature match was setup to work only on explicit invocations. However
this has shown to be too strict. Therefore, it's now a bit relaxed (not
as much as before): If the current item ends with the typed character we
assume  this is intenional - general premature matches do not end with
identifier characters anyway.

Note: Leaving only the last character as the condition is not an option
since sometimes they are not shown in the proposal description.

This patch also lifts the text method to IAssistProposalItem since
it's reasonable the every proposal must have at least some description.

Change-Id: I2ef7de2b7f978ce7059cce50175137a03315f495
Reviewed-on: http://codereview.qt.nokia.com/675
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Christian Kamm <christian.d.kamm@nokia.com>
---
 src/plugins/texteditor/codeassist/basicproposalitem.cpp     | 2 +-
 src/plugins/texteditor/codeassist/basicproposalitem.h       | 2 +-
 src/plugins/texteditor/codeassist/genericproposalwidget.cpp | 4 ++--
 src/plugins/texteditor/codeassist/iassistproposalitem.h     | 5 ++---
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/plugins/texteditor/codeassist/basicproposalitem.cpp b/src/plugins/texteditor/codeassist/basicproposalitem.cpp
index f1d0045f194..769a10b4fb0 100644
--- a/src/plugins/texteditor/codeassist/basicproposalitem.cpp
+++ b/src/plugins/texteditor/codeassist/basicproposalitem.cpp
@@ -61,7 +61,7 @@ void BasicProposalItem::setText(const QString &text)
     m_text = text;
 }
 
-const QString &BasicProposalItem::text() const
+QString BasicProposalItem::text() const
 {
     return m_text;
 }
diff --git a/src/plugins/texteditor/codeassist/basicproposalitem.h b/src/plugins/texteditor/codeassist/basicproposalitem.h
index 4478fb8fb21..2caa2b89c1f 100644
--- a/src/plugins/texteditor/codeassist/basicproposalitem.h
+++ b/src/plugins/texteditor/codeassist/basicproposalitem.h
@@ -52,7 +52,7 @@ public:
     const QIcon &icon() const;
 
     void setText(const QString &text);
-    const QString &text() const;
+    virtual QString text() const;
 
     void setDetail(const QString &detail);
     const QString &detail() const;
diff --git a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp
index 883e8897b42..6cece65adf0 100644
--- a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp
+++ b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp
@@ -604,12 +604,12 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
 
         if (ke->text().length() == 1
                 && m_d->m_completionListView->currentIndex().isValid()
-                && m_d->m_reason == ExplicitlyInvoked
                 && qApp->focusWidget() == o) {
             const QChar &typedChar = ke->text().at(0);
             IAssistProposalItem *item =
                 m_d->m_model->proposalItem(m_d->m_completionListView->currentIndex().row());
-            if (item->prematurelyApplies(typedChar)) {
+            if (item->prematurelyApplies(typedChar)
+                    && (m_d->m_reason == ExplicitlyInvoked || item->text().endsWith(typedChar))) {
                 abort();
                 emit proposalItemActivated(item);
                 return true;
diff --git a/src/plugins/texteditor/codeassist/iassistproposalitem.h b/src/plugins/texteditor/codeassist/iassistproposalitem.h
index 319a9344635..109da945c5f 100644
--- a/src/plugins/texteditor/codeassist/iassistproposalitem.h
+++ b/src/plugins/texteditor/codeassist/iassistproposalitem.h
@@ -35,9 +35,7 @@
 
 #include <texteditor/texteditor_global.h>
 
-QT_BEGIN_NAMESPACE
-class QChar;
-QT_END_NAMESPACE
+#include <QtCore/QString>
 
 namespace TextEditor {
 
@@ -49,6 +47,7 @@ public:
     IAssistProposalItem();
     virtual ~IAssistProposalItem();
 
+    virtual QString text() const = 0;
     virtual bool implicitlyApplies() const = 0;
     virtual bool prematurelyApplies(const QChar &c) const = 0;
     virtual void apply(BaseTextEditor *editor, int basePosition) const = 0;
-- 
GitLab