Commit be1311e3 authored by Aleksei Nikiforov's avatar Aleksei Nikiforov Committed by Yuri Chornoivan
Browse files

Contents tree: add fallback to URL without fragment

Differential revision: https://phabricator.kde.org/D27774
parent 65dfa07f
...@@ -295,10 +295,12 @@ void Navigator::selectItem( const QUrl &url ) ...@@ -295,10 +295,12 @@ void Navigator::selectItem( const QUrl &url )
// Make sure that we match both the original URL as well as // Make sure that we match both the original URL as well as
// its counterpart. // its counterpart.
QUrl alternativeURL = url; QUrl alternativeURL = url;
QUrl contentsItemURL = url;
if (url.hasFragment()) if (url.hasFragment())
{ {
alternativeURL.setQuery(QStringLiteral("anchor=")+url.fragment()); alternativeURL.setQuery(QStringLiteral("anchor=")+url.fragment());
alternativeURL.setFragment(QString()); alternativeURL.setFragment(QString());
contentsItemURL.setFragment(QString());
} }
// If the navigator already has the given URL selected, do nothing. // If the navigator already has the given URL selected, do nothing.
...@@ -323,22 +325,32 @@ void Navigator::selectItem( const QUrl &url ) ...@@ -323,22 +325,32 @@ void Navigator::selectItem( const QUrl &url )
} }
} }
NavigatorItem *contentsItem = nullptr;
QTreeWidgetItemIterator it( mContentsTree ); QTreeWidgetItemIterator it( mContentsTree );
while ( (*it) ) { while ( (*it) ) {
NavigatorItem *item = static_cast<NavigatorItem *>( (*it) ); NavigatorItem *item = static_cast<NavigatorItem *>( (*it) );
QUrl itemUrl( item->entry()->url() ); QUrl itemUrl( item->entry()->url() );
if ( (itemUrl == url) || (itemUrl == alternativeURL) ) { if ( (itemUrl == url) || (itemUrl == alternativeURL) ) {
mContentsTree->setCurrentItem( item );
// If the current item was not selected and remained unchanged it // If the current item was not selected and remained unchanged it
// needs to be explicitly selected // needs to be explicitly selected
mContentsTree->setCurrentItem(item); mContentsTree->setCurrentItem(item);
item->setExpanded( true ); item->setExpanded( true );
break; break;
} }
if ( (contentsItem == nullptr) && (itemUrl == contentsItemURL) ) {
contentsItem = item;
}
++it; ++it;
} }
if ( !(*it) ) { if ( !(*it) ) {
clearSelection(); // if search with fragment didn't find anything, but item without fragment was found, use it
if ( contentsItem != nullptr ) {
mContentsTree->setCurrentItem(contentsItem);
item->setExpanded( true );
mSelected = true;
} else {
clearSelection();
}
} else { } else {
mSelected = true; mSelected = true;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment