From 517400e7f6fc345ab69daf6f49b7068752452d8e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 2 Mar 2023 13:12:56 +0100 Subject: [PATCH] Copilot: do not activate the editor when requesting completions This has unwanted side effects like closing the completion and switching the current editor. Change-Id: Ic0e150f2377a731910e409b9edc959fda670cd99 Reviewed-by: Marcus Tillmanns Reviewed-by: hjk --- src/plugins/copilot/documentwatcher.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/plugins/copilot/documentwatcher.cpp b/src/plugins/copilot/documentwatcher.cpp index a11ff8bbec3..69b201b5216 100644 --- a/src/plugins/copilot/documentwatcher.cpp +++ b/src/plugins/copilot/documentwatcher.cpp @@ -37,12 +37,13 @@ DocumentWatcher::DocumentWatcher(CopilotClient *client, TextDocument *textDocume void DocumentWatcher::getSuggestion() { - Core::IEditor *editor = Core::EditorManager::instance()->activateEditorForDocument( - m_textDocument); - if (!editor) - return; - TextEditor::TextEditorWidget *textEditorWidget = qobject_cast( - editor->widget()); + TextEditorWidget *textEditorWidget = nullptr; + for (Core::IEditor *editor : Core::DocumentModel::editorsForDocument(m_textDocument)) { + textEditorWidget = qobject_cast(editor->widget()); + if (textEditorWidget) + break; + } + if (!textEditorWidget) return; @@ -50,12 +51,12 @@ void DocumentWatcher::getSuggestion() if (cursor.hasMultipleCursors() || cursor.hasSelection()) return; - const int currentCursorPos = cursor.cursors().first().position(); + const int currentCursorPos = cursor.mainCursor().position(); m_client->requestCompletion( m_textDocument->filePath(), m_client->documentVersion(m_textDocument->filePath()), - Position(editor->currentLine() - 1, editor->currentColumn() - 1), + Position(cursor.mainCursor()), [this, textEditorWidget, currentCursorPos](const GetCompletionRequest::Response &response) { if (response.error()) { qDebug() << "ERROR:" << *response.error();