forked from qt-creator/qt-creator
CodeAssist: move destroy context condition to function
Increasing readability by moving complex construct into own function. Change-Id: I4cad1a279293e3348f550e7c423d356d9c79769f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -91,6 +91,7 @@ private:
|
|||||||
void handlePrefixExpansion(const QString &newPrefix);
|
void handlePrefixExpansion(const QString &newPrefix);
|
||||||
void finalizeProposal();
|
void finalizeProposal();
|
||||||
void explicitlyAborted();
|
void explicitlyAborted();
|
||||||
|
bool isDestroyEvent(int key, const QString &keyText);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CodeAssistant *q = nullptr;
|
CodeAssistant *q = nullptr;
|
||||||
@@ -507,6 +508,15 @@ void CodeAssistantPrivate::clearAbortedPosition()
|
|||||||
m_abortedBasePosition = -1;
|
m_abortedBasePosition = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CodeAssistantPrivate::isDestroyEvent(int key, const QString &keyText)
|
||||||
|
{
|
||||||
|
if (keyText.isEmpty())
|
||||||
|
return key != Qt::LeftArrow && key != Qt::RightArrow && key != Qt::Key_Shift;
|
||||||
|
else if (auto *provider = dynamic_cast<CompletionAssistProvider *>(m_requestProvider))
|
||||||
|
return !provider->isContinuationChar(keyText.at(0));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CodeAssistantPrivate::eventFilter(QObject *o, QEvent *e)
|
bool CodeAssistantPrivate::eventFilter(QObject *o, QEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(o);
|
Q_UNUSED(o);
|
||||||
@@ -519,21 +529,12 @@ bool CodeAssistantPrivate::eventFilter(QObject *o, QEvent *e)
|
|||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
|
||||||
const QString &keyText = keyEvent->text();
|
const QString &keyText = keyEvent->text();
|
||||||
|
|
||||||
CompletionAssistProvider *completionProvider = nullptr;
|
if (isDestroyEvent(keyEvent->key(), keyText))
|
||||||
if ((keyText.isEmpty()
|
|
||||||
&& keyEvent->key() != Qt::LeftArrow
|
|
||||||
&& keyEvent->key() != Qt::RightArrow
|
|
||||||
&& keyEvent->key() != Qt::Key_Shift)
|
|
||||||
|| (!keyText.isEmpty()
|
|
||||||
&& (((completionProvider = dynamic_cast<CompletionAssistProvider *>(m_requestProvider))
|
|
||||||
? !completionProvider->isContinuationChar(keyText.at(0))
|
|
||||||
: false)))) {
|
|
||||||
destroyContext();
|
destroyContext();
|
||||||
} else if (!keyText.isEmpty() && !m_receivedContentWhileWaiting) {
|
else if (!keyText.isEmpty() && !m_receivedContentWhileWaiting)
|
||||||
m_receivedContentWhileWaiting = true;
|
m_receivedContentWhileWaiting = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user