fix(tabs): sync the sidebar selection with the tab actually switched to

main
reionwong 3 weeks ago
parent cc2b984d41
commit 69a6c0f2d5

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

@ -32,6 +32,8 @@ private slots:
QObject *window = engine.rootObjects().first();
QObject *menuBar = window->findChild<QObject *>("applicationMenuBar");
QVERIFY(menuBar);
QObject *sideBar = window->findChild<QObject *>("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);

Loading…
Cancel
Save