diff --git a/src/lib/navigation/completer/locationcompletermodel.cpp b/src/lib/navigation/completer/locationcompletermodel.cpp index 88ab9a6fe..7aff40a80 100644 --- a/src/lib/navigation/completer/locationcompletermodel.cpp +++ b/src/lib/navigation/completer/locationcompletermodel.cpp @@ -39,6 +39,7 @@ bool countBiggerThan(const QStandardItem* i1, const QStandardItem* i2) void LocationCompleterModel::refreshCompletions(const QString &string) { if (m_lastCompletion == string) { + refreshTabPositions(); return; } @@ -199,12 +200,17 @@ QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const } TabPosition LocationCompleterModel::tabPositionForUrl(const QUrl& url) const +{ + return tabPositionForEncodedUrl(url.toEncoded()); +} + +TabPosition LocationCompleterModel::tabPositionForEncodedUrl(const QString& encodedUrl) const { for(int win=0; win < mApp->windowCount(); ++win) { QupZilla* mainWin = mApp->mainWindows().at(win); QList tabs = mainWin->tabWidget()->allTabs(); for(int tab=0; tab < tabs.count(); ++tab) { - if(tabs[tab]->url() == url) { + if(tabs[tab]->url().toEncoded() == encodedUrl) { TabPosition pos; pos.windowIndex = win; pos.tabIndex = tab; @@ -214,3 +220,18 @@ TabPosition LocationCompleterModel::tabPositionForUrl(const QUrl& url) const } return TabPosition(); } + +void LocationCompleterModel::refreshTabPositions() +{ + if (!qzSettings->showSwitchTab) { + return; + } + + for (int row = 0; row < rowCount(); ++row) { + QStandardItem* aItem = item(row); + if (!aItem) { + continue; + } + aItem->setData(QVariant::fromValue(tabPositionForEncodedUrl(aItem->text())), TabPositionRole); + } +} diff --git a/src/lib/navigation/completer/locationcompletermodel.h b/src/lib/navigation/completer/locationcompletermodel.h index d3f046eab..73d497438 100644 --- a/src/lib/navigation/completer/locationcompletermodel.h +++ b/src/lib/navigation/completer/locationcompletermodel.h @@ -62,6 +62,8 @@ private: QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList &alreadyFound, int limit, bool bookmarks = false, bool exactMatch = false); TabPosition tabPositionForUrl(const QUrl& url) const; + TabPosition tabPositionForEncodedUrl(const QString& encodedUrl) const; + void refreshTabPositions(); QString m_lastCompletion; }; diff --git a/src/lib/navigation/completer/locationcompleterview.cpp b/src/lib/navigation/completer/locationcompleterview.cpp index d178d20eb..e963edf3d 100644 --- a/src/lib/navigation/completer/locationcompleterview.cpp +++ b/src/lib/navigation/completer/locationcompleterview.cpp @@ -269,8 +269,12 @@ void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event) void LocationCompleterView::activateTab(TabPosition pos) { - emit aboutToActivateTab(pos); QupZilla* win = mApp->mainWindows().at(pos.windowIndex); - win->activateWindow(); - win->tabWidget()->setCurrentIndex(pos.tabIndex); + if (mApp->getWindow() != win || mApp->getWindow()->tabWidget()->currentIndex() != pos.tabIndex) { + emit aboutToActivateTab(pos); + win->tabWidget()->setCurrentIndex(pos.tabIndex); + win->show(); + win->activateWindow(); + win->raise(); + } }