CodeAssist: Relax a bit premature match

In a relatively recent commit (99fee33fd1)
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>
This commit is contained in:
Leandro Melo
2011-06-23 15:35:07 +02:00
committed by Leandro T. C. Melo
parent a457124c54
commit 395ba9875a
4 changed files with 6 additions and 7 deletions

View File

@@ -61,7 +61,7 @@ void BasicProposalItem::setText(const QString &text)
m_text = text; m_text = text;
} }
const QString &BasicProposalItem::text() const QString BasicProposalItem::text() const
{ {
return m_text; return m_text;
} }

View File

@@ -52,7 +52,7 @@ public:
const QIcon &icon() const; const QIcon &icon() const;
void setText(const QString &text); void setText(const QString &text);
const QString &text() const; virtual QString text() const;
void setDetail(const QString &detail); void setDetail(const QString &detail);
const QString &detail() const; const QString &detail() const;

View File

@@ -604,12 +604,12 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
if (ke->text().length() == 1 if (ke->text().length() == 1
&& m_d->m_completionListView->currentIndex().isValid() && m_d->m_completionListView->currentIndex().isValid()
&& m_d->m_reason == ExplicitlyInvoked
&& qApp->focusWidget() == o) { && qApp->focusWidget() == o) {
const QChar &typedChar = ke->text().at(0); const QChar &typedChar = ke->text().at(0);
IAssistProposalItem *item = IAssistProposalItem *item =
m_d->m_model->proposalItem(m_d->m_completionListView->currentIndex().row()); 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(); abort();
emit proposalItemActivated(item); emit proposalItemActivated(item);
return true; return true;

View File

@@ -35,9 +35,7 @@
#include <texteditor/texteditor_global.h> #include <texteditor/texteditor_global.h>
QT_BEGIN_NAMESPACE #include <QtCore/QString>
class QChar;
QT_END_NAMESPACE
namespace TextEditor { namespace TextEditor {
@@ -49,6 +47,7 @@ public:
IAssistProposalItem(); IAssistProposalItem();
virtual ~IAssistProposalItem(); virtual ~IAssistProposalItem();
virtual QString text() const = 0;
virtual bool implicitlyApplies() const = 0; virtual bool implicitlyApplies() const = 0;
virtual bool prematurelyApplies(const QChar &c) const = 0; virtual bool prematurelyApplies(const QChar &c) const = 0;
virtual void apply(BaseTextEditor *editor, int basePosition) const = 0; virtual void apply(BaseTextEditor *editor, int basePosition) const = 0;