forked from qt-creator/qt-creator
LanguageClient: Do not add hover handler twice to editor
Check whether an editor already contains the hover handler before adding to the list of handlers. Also remove the handler when a document is deactivated for a specific client. Change-Id: Iec1d3a0fd1dc3f02c8dd50b8968ff063efe2508a Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -377,7 +377,7 @@ void Client::activateDocument(TextEditor::TextDocument *document)
|
|||||||
for (Core::IEditor *editor : Core::DocumentModel::editorsForDocument(document)) {
|
for (Core::IEditor *editor : Core::DocumentModel::editorsForDocument(document)) {
|
||||||
updateEditorToolBar(editor);
|
updateEditorToolBar(editor);
|
||||||
if (auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor))
|
if (auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor))
|
||||||
textEditor->editorWidget()->addHoverHandler(hoverHandler());
|
textEditor->editorWidget()->addHoverHandler(&m_hoverHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,6 +387,10 @@ void Client::deactivateDocument(TextEditor::TextDocument *document)
|
|||||||
resetAssistProviders(document);
|
resetAssistProviders(document);
|
||||||
if (TextEditor::SyntaxHighlighter *highlighter = document->syntaxHighlighter())
|
if (TextEditor::SyntaxHighlighter *highlighter = document->syntaxHighlighter())
|
||||||
highlighter->clearAllExtraFormats();
|
highlighter->clearAllExtraFormats();
|
||||||
|
for (Core::IEditor *editor : Core::DocumentModel::editorsForDocument(document)) {
|
||||||
|
if (auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor))
|
||||||
|
textEditor->editorWidget()->removeHoverHandler(&m_hoverHandler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::documentOpen(TextEditor::TextDocument *document) const
|
bool Client::documentOpen(TextEditor::TextDocument *document) const
|
||||||
|
@@ -5640,7 +5640,8 @@ void TextEditorWidget::showDefaultContextMenu(QContextMenuEvent *e, Id menuConte
|
|||||||
|
|
||||||
void TextEditorWidget::addHoverHandler(BaseHoverHandler *handler)
|
void TextEditorWidget::addHoverHandler(BaseHoverHandler *handler)
|
||||||
{
|
{
|
||||||
d->m_hoverHandlers.append(handler);
|
if (!d->m_hoverHandlers.contains(handler))
|
||||||
|
d->m_hoverHandlers.append(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidget::removeHoverHandler(BaseHoverHandler *handler)
|
void TextEditorWidget::removeHoverHandler(BaseHoverHandler *handler)
|
||||||
|
Reference in New Issue
Block a user