diff --git a/qml/main.qml b/qml/main.qml index f6b993f..223d270 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -64,19 +64,25 @@ FishUI.Window { var page = tabs[index] var remaining = tabs.slice() remaining.splice(index, 1) - currentTab = Math.max(0, currentTab - (index <= currentTab ? 1 : 0)) + // The list has to shrink before the index moves, or the sync that + // follows the index change still sees the tab being closed. tabs = remaining + currentTab = Math.max(0, currentTab - (index <= currentTab ? 1 : 0)) page.destroy() syncNavigation() } function syncNavigation() { - if (!_folderPage) + // Not _folderPage: its binding on currentTab has not been re-evaluated + // yet when this runs from onCurrentTabChanged, so it still holds the + // tab we are leaving. + var page = tabs.length ? tabs[currentTab] : null + if (!page) return _pathBar.closeEditor() - _sideBar.updateSelection(_folderPage.currentUrl) - _pathBar.updateUrl(_folderPage.currentUrl) - _folderPage.focusView() + _sideBar.updateSelection(page.currentUrl) + _pathBar.updateUrl(page.currentUrl) + page.focusView() } function moveTab(from, to) { @@ -277,6 +283,7 @@ FishUI.Window { SideBar { id: _sideBar + objectName: "sideBar" Layout.fillHeight: true title: root.title onClicked: _folderPage.openUrl(path) diff --git a/tests/tst_tabs.cpp b/tests/tst_tabs.cpp index 3b7b4f8..694cbe9 100644 --- a/tests/tst_tabs.cpp +++ b/tests/tst_tabs.cpp @@ -32,6 +32,8 @@ private slots: QObject *window = engine.rootObjects().first(); QObject *menuBar = window->findChild("applicationMenuBar"); QVERIFY(menuBar); + QObject *sideBar = window->findChild("sideBar"); + QVERIFY(sideBar); QSignalSpy menuWindowChanges(menuBar, SIGNAL(windowChanged())); QVERIFY(menuWindowChanges.isValid()); auto evaluate = [&](const QString &code) { @@ -79,6 +81,8 @@ private slots: window->setProperty("currentTab", 0); QCOMPARE(activePage(), firstPage); + // Switching tabs has to move the sidebar selection with it. + QCOMPARE(sideBar->property("selectedPath").toString(), firstUrl); QCOMPARE(firstModel->url(), firstUrl); QVERIFY(firstModel->canGoBack()); firstModel->goBack(); @@ -109,6 +113,7 @@ private slots: QTRY_COMPARE(evaluate("tabs.length").toInt(), 2); QTest::keyClick(quickWindow, Qt::Key_Tab, Qt::ControlModifier); QTRY_COMPARE(window->property("currentTab").toInt(), 0); + QCOMPARE(sideBar->property("selectedPath").toString(), initialUrl); QTest::keyClick(quickWindow, Qt::Key_W, Qt::ControlModifier); QTRY_COMPARE(evaluate("tabs.length").toInt(), 1);