Fix crash on text hint being triggered after disabling code browser plugin

From KTextEditor::TextHintInterface::registerTextHintProvider() docs:
"When the provider is about to be destroyed, make sure to call
unregisterTextHintProvider() to avoid a dangling pointer."
(new requirement with KF5)

The old code never unregistered in case the ContextBrowserPlugin was
deleted (like it happens when disabling the plugin in the settings in
a running KDevelop instance).

CCBUG: 411371
parent c7254e73
Pipeline #7251 failed with stage
in 60 minutes
......@@ -329,6 +329,11 @@ ContextBrowserPlugin::ContextBrowserPlugin(QObject* parent, const QVariantList&)
ContextBrowserPlugin::~ContextBrowserPlugin()
{
for (auto* view : qAsConst(m_textHintProvidedViews)) {
auto* iface = qobject_cast<KTextEditor::TextHintInterface*>(view);
iface->unregisterTextHintProvider(&m_textHintProvider);
}
///TODO: QObject inheritance should suffice?
delete m_nextMenu;
delete m_previousMenu;
......@@ -976,6 +981,7 @@ void ContextBrowserPlugin::viewDestroyed(QObject* obj)
{
m_highlightedRanges.remove(static_cast<KTextEditor::View*>(obj));
m_updateViews.remove(static_cast<View*>(obj));
m_textHintProvidedViews.removeOne(static_cast<KTextEditor::View*>(obj));
}
void ContextBrowserPlugin::selectionChanged(View* view)
......@@ -1024,8 +1030,12 @@ void ContextBrowserPlugin::viewCreated(KTextEditor::Document*, View* v)
if (!iface)
return;
if (m_textHintProvidedViews.contains(v)) {
return;
}
iface->setTextHintDelay(highlightingTimeout);
iface->registerTextHintProvider(&m_textHintProvider);
m_textHintProvidedViews.append(v);
}
void ContextBrowserPlugin::registerToolView(ContextBrowserView* view)
......
......@@ -228,6 +228,8 @@ private:
//Holds a list of all active context browser tool views
QList<ContextBrowserView*> m_views;
QVector<KTextEditor::View*> m_textHintProvidedViews;
//Used to override the next declaration that will be highlighted
KDevelop::IndexedDeclaration m_useDeclaration;
KDevelop::IndexedDeclaration m_lastHighlightedDeclaration;
......
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