From 5f8ffd66ff1b1383bc4caff0c8dc725ee3966d1e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 6 Jun 2024 09:30:17 +0200 Subject: [PATCH] QmlJSEditor: fix assigning outline toolbar widget Instead of adding a second toolbar widget, replace the current one. This avoids weird situations where you get two outline toolbar widgets, one provided by qmljseditorwidget and another one provided by qmlls. Turning the language server on deletes the combobox created by qmljseditorwidget, such that qmljseditorwidget has to recreate its combobox after the language server stopped being in use. Also make sure that m_outlineCombo is set to nullptr after it gets deleted, such that late jumpToOutlineElement and updateOutlineIndexNow() calls do no try to attempt stuff on an already free'd pointer. Change-Id: Ie323a7b3e7a4d5e24407fcedf8383dd2f0efe525 Reviewed-by: Ulf Hermann Reviewed-by: David Schulz Reviewed-by: Fabian Kosmale --- src/plugins/qmljseditor/qmljseditor.cpp | 17 ++++++++++++++++- src/plugins/qmljseditor/qmljseditor.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 540e5559de6..11dc5cf9ae8 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -267,6 +267,8 @@ bool QmlJSEditorWidget::isOutlineCursorChangesBlocked() void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/) { + if (!m_outlineCombo) + return; QModelIndex index = m_outlineCombo->view()->currentIndex(); SourceLocation location = m_qmlJsEditorDocument->outlineModel()->sourceLocation(index); @@ -285,6 +287,8 @@ void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/) void QmlJSEditorWidget::updateOutlineIndexNow() { + if (!m_outlineCombo) + return; if (!m_qmlJsEditorDocument->outlineModel()->document()) return; @@ -570,8 +574,19 @@ void QmlJSEditorWidget::createToolBar() connect(this, &QmlJSEditorWidget::cursorPositionChanged, &m_updateOutlineIndexTimer, QOverload<>::of(&QTimer::start)); + connect(this, &QmlJSEditorWidget::toolbarOutlineChanged, + this, &QmlJSEditorWidget::updateOutline); - insertExtraToolBarWidget(TextEditorWidget::Left, m_outlineCombo); + setToolbarOutline(m_outlineCombo); +} + +void QmlJSEditorWidget::updateOutline(QWidget *newOutline) +{ + if (!newOutline) { + createToolBar(); + } else if (newOutline != m_outlineCombo){ + m_outlineCombo = nullptr; + } } class CodeModelInspector : public MemberProcessor diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index d5279fe78e7..0929fa552a4 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -79,6 +79,7 @@ protected: void scrollContentsBy(int dx, int dy) override; void applyFontSettings() override; void createToolBar(); + void updateOutline(QWidget *newOutline); void findLinkAt(const QTextCursor &cursor, const Utils::LinkHandler &processLinkCallback, bool resolveTarget = true,