forked from qt-creator/qt-creator
TextEditor: fix crash after removing hover handler
If we remove a hover handler from the editor we have to reset the last cached hover result in the runner to prevent using this removed and potentially deleted hover handler. Change-Id: I2bbdbee9d018aac426832552d036926be9ff198e Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -325,25 +325,17 @@ public:
|
|||||||
if (isCheckRunning(documentRevision, position))
|
if (isCheckRunning(documentRevision, position))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
abortHandlers();
|
|
||||||
|
|
||||||
// Update invocation data
|
// Update invocation data
|
||||||
m_documentRevision = documentRevision;
|
m_documentRevision = documentRevision;
|
||||||
m_position = position;
|
m_position = position;
|
||||||
m_callback = callback;
|
m_callback = callback;
|
||||||
|
|
||||||
// Re-initialize process data
|
restart();
|
||||||
m_currentHandlerIndex = 0;
|
|
||||||
m_bestHandler = nullptr;
|
|
||||||
m_highestHandlerPriority = -1;
|
|
||||||
|
|
||||||
// Start checking
|
|
||||||
checkNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCheckRunning(int documentRevision, int position) const
|
bool isCheckRunning(int documentRevision, int position) const
|
||||||
{
|
{
|
||||||
return m_currentHandlerIndex <= m_handlers.size()
|
return m_currentHandlerIndex >= 0
|
||||||
&& m_documentRevision == documentRevision
|
&& m_documentRevision == documentRevision
|
||||||
&& m_position == position;
|
&& m_position == position;
|
||||||
}
|
}
|
||||||
@@ -376,6 +368,7 @@ public:
|
|||||||
checkNext();
|
checkNext();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
m_currentHandlerIndex = -1;
|
||||||
|
|
||||||
// All were queried, run the best
|
// All were queried, run the best
|
||||||
if (m_bestHandler) {
|
if (m_bestHandler) {
|
||||||
@@ -384,11 +377,36 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handlerRemoved(BaseHoverHandler *handler)
|
||||||
|
{
|
||||||
|
if (m_lastHandlerInfo.handler == handler)
|
||||||
|
m_lastHandlerInfo = LastHandlerInfo();
|
||||||
|
if (m_currentHandlerIndex >= 0)
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void abortHandlers()
|
void abortHandlers()
|
||||||
{
|
{
|
||||||
for (BaseHoverHandler *handler : m_handlers)
|
for (BaseHoverHandler *handler : m_handlers)
|
||||||
handler->abort();
|
handler->abort();
|
||||||
|
m_currentHandlerIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void restart()
|
||||||
|
{
|
||||||
|
abortHandlers();
|
||||||
|
|
||||||
|
if (m_handlers.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Re-initialize process data
|
||||||
|
m_currentHandlerIndex = 0;
|
||||||
|
m_bestHandler = nullptr;
|
||||||
|
m_highestHandlerPriority = -1;
|
||||||
|
|
||||||
|
// Start checking
|
||||||
|
checkNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorWidget *m_widget;
|
TextEditorWidget *m_widget;
|
||||||
@@ -5457,6 +5475,7 @@ void TextEditorWidget::addHoverHandler(BaseHoverHandler *handler)
|
|||||||
void TextEditorWidget::removeHoverHandler(BaseHoverHandler *handler)
|
void TextEditorWidget::removeHoverHandler(BaseHoverHandler *handler)
|
||||||
{
|
{
|
||||||
d->m_hoverHandlers.removeAll(handler);
|
d->m_hoverHandlers.removeAll(handler);
|
||||||
|
d->m_hoverHandlerRunner.handlerRemoved(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
|
Reference in New Issue
Block a user