From fbab5c096b59ce898da3d375e2371152d3a85de5 Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Tue, 21 Jun 2011 16:54:43 +0200 Subject: [PATCH] Completion: Restrict prefix and implicit mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Thorbjørn Lindeijer --- .../codeassist/genericproposalwidget.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp index 1485e9ea0ba..dd9f070a549 100644 --- a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp +++ b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp @@ -241,7 +241,7 @@ public: bool m_isSynchronized; bool m_explicitlySelected; AssistReason m_reason; - bool m_gotContent; + bool m_justInvoked; QPointer m_infoFrame; QTimer m_infoTimer; CodeAssistant *m_assistant; @@ -257,7 +257,7 @@ GenericProposalWidgetPrivate::GenericProposalWidgetPrivate(QWidget *completionWi , m_model(0) , m_isSynchronized(true) , m_explicitlySelected(false) - , m_gotContent(false) + , m_justInvoked(false) , m_assistant(0) { connect(m_completionListView, SIGNAL(activated(QModelIndex)), @@ -345,6 +345,8 @@ void GenericProposalWidget::setAssistant(CodeAssistant *assistant) void GenericProposalWidget::setReason(AssistReason reason) { m_d->m_reason = reason; + if (m_d->m_reason == ExplicitlyInvoked) + m_d->m_justInvoked = true; } void GenericProposalWidget::setUnderlyingWidget(const QWidget *underlyingWidget) @@ -378,8 +380,6 @@ void GenericProposalWidget::setIsSynchronized(bool isSync) void GenericProposalWidget::showProposal(const QString &prefix) { ensurePolished(); - if (!prefix.isEmpty()) - m_d->m_gotContent = true; m_d->m_model->removeDuplicates(); if (!updateAndCheck(prefix)) return; @@ -452,8 +452,7 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix) } if (TextEditorSettings::instance()->completionSettings().m_partiallyComplete - && m_d->m_reason == ExplicitlyInvoked - && m_d->m_gotContent + && m_d->m_justInvoked && m_d->m_isSynchronized) { if (m_d->m_model->size() == 1) { IAssistProposalItem *item = m_d->m_model->proposalItem(0); @@ -470,6 +469,9 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix) } } + if (m_d->m_justInvoked) + m_d->m_justInvoked = false; + updatePositionAndSize(); return true; } @@ -526,7 +528,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e) } } } else if (e->type() == QEvent::KeyPress) { - m_d->m_gotContent = false; QKeyEvent *ke = static_cast(e); switch (ke->key()) { case Qt::Key_Escape: @@ -546,7 +547,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e) m_d->m_completionListView->selectRow(newRow); return true; } - m_d->m_gotContent = true; break; case Qt::Key_Tab: @@ -592,7 +592,6 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e) // Only forward keys that insert text and refine the completion. if (ke->text().isEmpty()) return true; - m_d->m_gotContent = true; break; }