Commit d4e9b862 authored by Leandro Melo's avatar Leandro Melo Committed by Leandro T. C. Melo
Browse files

Completion: Fine tuning perfect match behavior

Keeping or not the completion popup upon a perfect match
is best identified by the model in question instead of simply
by the triggering reason. For instance, in QML we don't want
to preserve the popup if completion was triggered by an
activation sequence. On the other hand, this is ok for C++
since a semicolon or parenthesis will in general still be
typed (in some cases even with the intention to take advantage
of the automatic bracked insertion).

For more context see 271bd44d2c1daa43c125cc09e6af57bb756de857.

Change-Id: If9dbf33243b623c077ce027e7e46265d0fc4ba8b
Reviewed-on: http://codereview.qt.nokia.com/563

Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn@lindeijer.nl>
parent 3ed88e12
......@@ -852,3 +852,8 @@ void QmlJSAssistProposalModel::sort()
{
qSort(currentItems().first, currentItems().second, QmlJSLessThan());
}
bool QmlJSAssistProposalModel::keepPerfectMatch(TextEditor::AssistReason reason) const
{
return reason == ExplicitlyInvoked;
}
......@@ -75,6 +75,7 @@ public:
{}
virtual void sort();
virtual bool keepPerfectMatch(TextEditor::AssistReason reason) const;
};
......
......@@ -234,6 +234,11 @@ bool BasicProposalItemListModel::supportsPrefixExpansion() const
return true;
}
bool BasicProposalItemListModel::keepPerfectMatch(AssistReason reason) const
{
return reason != IdleEditor;
}
QString BasicProposalItemListModel::proposalPrefix() const
{
if (m_currentItems.size() >= kMaxPrefixFilter)
......
......@@ -64,6 +64,7 @@ public:
virtual void sort();
virtual bool supportsPrefixExpansion() const;
virtual QString proposalPrefix() const;
virtual bool keepPerfectMatch(AssistReason reason) const;
virtual IAssistProposalItem *proposalItem(int index) const;
void loadContent(const QList<BasicProposalItem *> &items);
......
......@@ -76,7 +76,7 @@ QString cleanText(const QString &original)
return clean;
}
bool hasMatch(const QString &prefix, const IGenericProposalModel *model)
bool isPerfectMatch(const QString &prefix, const IGenericProposalModel *model)
{
if (prefix.isEmpty())
return false;
......@@ -425,7 +425,8 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix)
if (!prefix.isEmpty())
m_d->m_model->filter(prefix);
if (m_d->m_model->size() == 0
|| (m_d->m_reason == IdleEditor && hasMatch(prefix, m_d->m_model))) {
|| (!m_d->m_model->keepPerfectMatch(m_d->m_reason)
&& isPerfectMatch(prefix, m_d->m_model))) {
abort();
return false;
}
......
......@@ -34,6 +34,7 @@
#define IGENERICPROPOSALMODEL_H
#include "iassistproposalmodel.h"
#include "assistenums.h"
#include <texteditor/texteditor_global.h>
......@@ -58,6 +59,7 @@ public:
virtual void sort() = 0;
virtual bool supportsPrefixExpansion() const = 0;
virtual QString proposalPrefix() const = 0;
virtual bool keepPerfectMatch(AssistReason reason) const = 0;
virtual IAssistProposalItem *proposalItem(int index) const = 0;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment