diff --git a/framework/dockwindow/qml/Muse/Dock/DockFrame.qml b/framework/dockwindow/qml/Muse/Dock/DockFrame.qml index f3684be519..4bec0547c4 100644 --- a/framework/dockwindow/qml/Muse/Dock/DockFrame.qml +++ b/framework/dockwindow/qml/Muse/Dock/DockFrame.qml @@ -64,7 +64,13 @@ Rectangle { QtObject { id: prv readonly property alias tabsModel: frameModel.tabsModel - readonly property int currentIndex: Boolean(root.frameCpp) && root.frameCpp.currentIndex >= 0 ? root.frameCpp.currentIndex : 0 + readonly property int currentIndex: { + const tabCount = prv.tabsModel.numTabs // re-evaluate when tabs are added or closed + if (tabCount <= 0 || !Boolean(root.frameCpp)) { + return 0 + } + return root.frameCpp.currentIndex >= 0 ? root.frameCpp.currentIndex : 0 + } } NavigationPanel { diff --git a/framework/dockwindow/qml/Muse/Dock/DockTabBar.qml b/framework/dockwindow/qml/Muse/Dock/DockTabBar.qml index dab16732cf..bbc38888dd 100644 --- a/framework/dockwindow/qml/Muse/Dock/DockTabBar.qml +++ b/framework/dockwindow/qml/Muse/Dock/DockTabBar.qml @@ -155,6 +155,24 @@ Rectangle { onHandleContextMenuItemRequested: function(itemId) { root.handleContextMenuItemRequested(itemId) } + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.MiddleButton + + onClicked: { + const closingCurrent = model.index === root.currentIndex + const previous = Math.max(0, model.index - 1) + + model.contextMenu.handleMenuItem("command://dock/set-open") + + if (closingCurrent) { + Qt.callLater(function() { + root.tabClicked(previous) + }) + } + } + } } }