LanguageClient: avoid updating current outline item

.. after we received new content for the outline if the user has
explicitly disabled the cursor synchronization.

Change-Id: Idc98457d26c094a6d420d282c71d50a2b19e1df7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2025-01-09 12:19:04 +01:00
parent 025efa0964
commit 3cb772cad8

View File

@@ -120,7 +120,7 @@ public:
private: private:
void handleResponse(const DocumentUri &uri, const DocumentSymbolsResult &response); void handleResponse(const DocumentUri &uri, const DocumentSymbolsResult &response);
void updateTextCursor(const QModelIndex &proxyIndex); void updateTextCursor(const QModelIndex &proxyIndex);
void updateSelectionInTree(const QTextCursor &currentCursor); void updateSelectionInTree();
void onItemActivated(const QModelIndex &index); void onItemActivated(const QModelIndex &index);
QPointer<Client> m_client; QPointer<Client> m_client;
@@ -168,10 +168,7 @@ LanguageClientOutlineWidget::LanguageClientOutlineWidget(Client *client,
connect(&m_view, &QAbstractItemView::activated, connect(&m_view, &QAbstractItemView::activated,
this, &LanguageClientOutlineWidget::onItemActivated); this, &LanguageClientOutlineWidget::onItemActivated);
connect(m_editor->editorWidget(), &TextEditor::TextEditorWidget::cursorPositionChanged, connect(m_editor->editorWidget(), &TextEditor::TextEditorWidget::cursorPositionChanged,
this, [this](){ this, &LanguageClientOutlineWidget::updateSelectionInTree);
if (m_sync)
updateSelectionInTree(m_editor->textCursor());
});
setFocusProxy(&m_view); setFocusProxy(&m_view);
} }
@@ -183,8 +180,7 @@ QList<QAction *> LanguageClientOutlineWidget::filterMenuActions() const
void LanguageClientOutlineWidget::setCursorSynchronization(bool syncWithCursor) void LanguageClientOutlineWidget::setCursorSynchronization(bool syncWithCursor)
{ {
m_sync = syncWithCursor; m_sync = syncWithCursor;
if (m_sync && m_editor) updateSelectionInTree();
updateSelectionInTree(m_editor->textCursor());
} }
void LanguageClientOutlineWidget::setSorted(bool sorted) void LanguageClientOutlineWidget::setSorted(bool sorted)
@@ -237,7 +233,7 @@ void LanguageClientOutlineWidget::handleResponse(const DocumentUri &uri,
m_view.expandAll(); m_view.expandAll();
// The list has changed, update the current items // The list has changed, update the current items
updateSelectionInTree(m_editor->textCursor()); updateSelectionInTree();
} }
void LanguageClientOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex) void LanguageClientOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex)
@@ -263,8 +259,11 @@ static LanguageClientOutlineItem *itemForCursor(const LanguageClientOutlineModel
return result; return result;
} }
void LanguageClientOutlineWidget::updateSelectionInTree(const QTextCursor &currentCursor) void LanguageClientOutlineWidget::updateSelectionInTree()
{ {
if (!m_sync || !m_editor)
return;
const QTextCursor currentCursor = m_editor->editorWidget()->textCursor();
if (LanguageClientOutlineItem *item = itemForCursor(m_model, currentCursor)) { if (LanguageClientOutlineItem *item = itemForCursor(m_model, currentCursor)) {
const QModelIndex index = m_proxyModel.mapFromSource(m_model.indexForItem(item)); const QModelIndex index = m_proxyModel.mapFromSource(m_model.indexForItem(item));
m_view.setCurrentIndex(index); m_view.setCurrentIndex(index);