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:
David Schulz
2019-11-06 10:14:13 +01:00
parent 005e7aa54d
commit 30587e6dce
2 changed files with 7 additions and 2 deletions

View File

@@ -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

View File

@@ -5640,6 +5640,7 @@ void TextEditorWidget::showDefaultContextMenu(QContextMenuEvent *e, Id menuConte
void TextEditorWidget::addHoverHandler(BaseHoverHandler *handler) void TextEditorWidget::addHoverHandler(BaseHoverHandler *handler)
{ {
if (!d->m_hoverHandlers.contains(handler))
d->m_hoverHandlers.append(handler); d->m_hoverHandlers.append(handler);
} }