Commit 1cfca296 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

TextEditor: Do not trigger autocomplete after user aborts...



... for the same function

Task-number: QTCREATORBUG-5748
Change-Id: Iadf5be76c24f95cf057c2112a8248bea2a9e20cf
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent c9a851c6
......@@ -40,6 +40,7 @@
#include <texteditor/basetexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/completionsettings.h>
#include <coreplugin/editormanager/editormanager.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
......@@ -113,6 +114,8 @@ private slots:
void finalizeProposal();
void automaticProposalTimeout();
void updateCompletionSettings(const TextEditor::CompletionSettings &settings);
void explicitlyAborted();
void clearAbortedPosition();
private:
CodeAssistant *m_q;
......@@ -127,6 +130,7 @@ private:
bool m_receivedContentWhileWaiting;
QTimer m_automaticProposalTimer;
CompletionSettings m_settings;
int m_abortedBasePosition;
static const QChar m_null;
};
......@@ -148,6 +152,7 @@ CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
, m_proposalWidget(0)
, m_receivedContentWhileWaiting(false)
, m_settings(TextEditorSettings::instance()->completionSettings())
, m_abortedBasePosition(-1)
{
m_automaticProposalTimer.setSingleShot(true);
m_automaticProposalTimer.setInterval(AutomaticProposalTimerInterval);
......@@ -157,6 +162,8 @@ CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
this,
SLOT(updateCompletionSettings(TextEditor::CompletionSettings)));
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(clearAbortedPosition()));
}
CodeAssistantPrivate::~CodeAssistantPrivate()
......@@ -307,33 +314,41 @@ void CodeAssistantPrivate::displayProposal(IAssistProposal *newProposal, AssistR
destroyContext();
}
if (m_textEditor->position() < proposalCandidate->basePosition())
int basePosition = proposalCandidate->basePosition();
if (m_textEditor->position() < basePosition)
return;
if (m_abortedBasePosition == basePosition && reason != ExplicitlyInvoked)
return;
clearAbortedPosition();
m_proposal.reset(proposalCandidate.take());
if (m_proposal->isCorrective())
m_proposal->makeCorrection(m_textEditor);
basePosition = m_proposal->basePosition();
m_proposalWidget = m_proposal->createWidget();
connect(m_proposalWidget, SIGNAL(destroyed()), this, SLOT(finalizeProposal()));
connect(m_proposalWidget, SIGNAL(prefixExpanded(QString)),
this, SLOT(handlePrefixExpansion(QString)));
connect(m_proposalWidget, SIGNAL(proposalItemActivated(IAssistProposalItem*)),
this, SLOT(processProposalItem(IAssistProposalItem*)));
connect(m_proposalWidget, SIGNAL(explicitlyAborted()),
this, SLOT(explicitlyAborted()));
m_proposalWidget->setAssistant(m_q);
m_proposalWidget->setReason(reason);
m_proposalWidget->setKind(m_assistKind);
m_proposalWidget->setUnderlyingWidget(m_textEditor->widget());
m_proposalWidget->setModel(m_proposal->model());
m_proposalWidget->setDisplayRect(m_textEditor->cursorRect(m_proposal->basePosition()));
m_proposalWidget->setDisplayRect(m_textEditor->cursorRect(basePosition));
if (m_receivedContentWhileWaiting)
m_proposalWidget->setIsSynchronized(false);
else
m_proposalWidget->setIsSynchronized(true);
m_proposalWidget->showProposal(m_textEditor->textDocument()->textAt(
m_proposal->basePosition(),
m_textEditor->position() - m_proposal->basePosition()));
basePosition,
m_textEditor->position() - basePosition));
}
void CodeAssistantPrivate::processProposalItem(IAssistProposalItem *proposalItem)
......@@ -465,6 +480,17 @@ void CodeAssistantPrivate::updateCompletionSettings(const TextEditor::Completion
m_settings = settings;
}
void CodeAssistantPrivate::explicitlyAborted()
{
QTC_ASSERT(m_proposal, return);
m_abortedBasePosition = m_proposal->basePosition();
}
void CodeAssistantPrivate::clearAbortedPosition()
{
m_abortedBasePosition = -1;
}
bool CodeAssistantPrivate::eventFilter(QObject *o, QEvent *e)
{
Q_UNUSED(o);
......
......@@ -215,6 +215,7 @@ bool FunctionHintProposalWidget::eventFilter(QObject *obj, QEvent *e)
case QEvent::KeyRelease:
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && d->m_escapePressed) {
abort();
emit explicitlyAborted();
return false;
}
d->m_assistant->notifyChange();
......
......@@ -571,6 +571,7 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
switch (ke->key()) {
case Qt::Key_Escape:
abort();
emit explicitlyAborted();
e->accept();
return true;
......
......@@ -65,6 +65,7 @@ public:
signals:
void prefixExpanded(const QString &newPrefix);
void proposalItemActivated(IAssistProposalItem *proposalItem);
void explicitlyAborted();
};
} // TextEditor
......
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