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

Completion: Restrict prefix and implicit mode

Automatic prefix and implicit completion should only
happen when the setting allows, the popup is synchronized,
and the completion has just been invoked. This means that
if characters are typed afterwards they should not trigger
such behavior.

Change-Id: Iedfc4211d171a21ef0a2daaa475d291e756e7cc0
Reviewed-on: http://codereview.qt.nokia.com/570

Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn@lindeijer.nl>
parent d4e9b862
...@@ -241,7 +241,7 @@ public: ...@@ -241,7 +241,7 @@ public:
bool m_isSynchronized; bool m_isSynchronized;
bool m_explicitlySelected; bool m_explicitlySelected;
AssistReason m_reason; AssistReason m_reason;
bool m_gotContent; bool m_justInvoked;
QPointer<GenericProposalInfoFrame> m_infoFrame; QPointer<GenericProposalInfoFrame> m_infoFrame;
QTimer m_infoTimer; QTimer m_infoTimer;
CodeAssistant *m_assistant; CodeAssistant *m_assistant;
...@@ -257,7 +257,7 @@ GenericProposalWidgetPrivate::GenericProposalWidgetPrivate(QWidget *completionWi ...@@ -257,7 +257,7 @@ GenericProposalWidgetPrivate::GenericProposalWidgetPrivate(QWidget *completionWi
, m_model(0) , m_model(0)
, m_isSynchronized(true) , m_isSynchronized(true)
, m_explicitlySelected(false) , m_explicitlySelected(false)
, m_gotContent(false) , m_justInvoked(false)
, m_assistant(0) , m_assistant(0)
{ {
connect(m_completionListView, SIGNAL(activated(QModelIndex)), connect(m_completionListView, SIGNAL(activated(QModelIndex)),
...@@ -345,6 +345,8 @@ void GenericProposalWidget::setAssistant(CodeAssistant *assistant) ...@@ -345,6 +345,8 @@ void GenericProposalWidget::setAssistant(CodeAssistant *assistant)
void GenericProposalWidget::setReason(AssistReason reason) void GenericProposalWidget::setReason(AssistReason reason)
{ {
m_d->m_reason = reason; m_d->m_reason = reason;
if (m_d->m_reason == ExplicitlyInvoked)
m_d->m_justInvoked = true;
} }
void GenericProposalWidget::setUnderlyingWidget(const QWidget *underlyingWidget) void GenericProposalWidget::setUnderlyingWidget(const QWidget *underlyingWidget)
...@@ -378,8 +380,6 @@ void GenericProposalWidget::setIsSynchronized(bool isSync) ...@@ -378,8 +380,6 @@ void GenericProposalWidget::setIsSynchronized(bool isSync)
void GenericProposalWidget::showProposal(const QString &prefix) void GenericProposalWidget::showProposal(const QString &prefix)
{ {
ensurePolished(); ensurePolished();
if (!prefix.isEmpty())
m_d->m_gotContent = true;
m_d->m_model->removeDuplicates(); m_d->m_model->removeDuplicates();
if (!updateAndCheck(prefix)) if (!updateAndCheck(prefix))
return; return;
...@@ -452,8 +452,7 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix) ...@@ -452,8 +452,7 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix)
} }
if (TextEditorSettings::instance()->completionSettings().m_partiallyComplete if (TextEditorSettings::instance()->completionSettings().m_partiallyComplete
&& m_d->m_reason == ExplicitlyInvoked && m_d->m_justInvoked
&& m_d->m_gotContent
&& m_d->m_isSynchronized) { && m_d->m_isSynchronized) {
if (m_d->m_model->size() == 1) { if (m_d->m_model->size() == 1) {
IAssistProposalItem *item = m_d->m_model->proposalItem(0); IAssistProposalItem *item = m_d->m_model->proposalItem(0);
...@@ -470,6 +469,9 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix) ...@@ -470,6 +469,9 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix)
} }
} }
if (m_d->m_justInvoked)
m_d->m_justInvoked = false;
updatePositionAndSize(); updatePositionAndSize();
return true; return true;
} }
...@@ -526,7 +528,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e) ...@@ -526,7 +528,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
} }
} }
} else if (e->type() == QEvent::KeyPress) { } else if (e->type() == QEvent::KeyPress) {
m_d->m_gotContent = false;
QKeyEvent *ke = static_cast<QKeyEvent *>(e); QKeyEvent *ke = static_cast<QKeyEvent *>(e);
switch (ke->key()) { switch (ke->key()) {
case Qt::Key_Escape: case Qt::Key_Escape:
...@@ -546,7 +547,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e) ...@@ -546,7 +547,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
m_d->m_completionListView->selectRow(newRow); m_d->m_completionListView->selectRow(newRow);
return true; return true;
} }
m_d->m_gotContent = true;
break; break;
case Qt::Key_Tab: case Qt::Key_Tab:
...@@ -592,7 +592,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e) ...@@ -592,7 +592,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
// Only forward keys that insert text and refine the completion. // Only forward keys that insert text and refine the completion.
if (ke->text().isEmpty()) if (ke->text().isEmpty())
return true; return true;
m_d->m_gotContent = true;
break; break;
} }
......
Supports Markdown
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