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 <ulf.hermann@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
David Schulz
2024-06-06 09:30:17 +02:00
committed by Sami Shalayel
parent 441ce652e7
commit 5f8ffd66ff
2 changed files with 17 additions and 1 deletions

View File

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

View File

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