+
+ // Is dirContainingItem expanded in some tree-style view?
+ // The rest of this method is about figuring this out.
+
+ int i = currentIndex();
+ if (i < 0) {
+ return std::nullopt;
+ }
+ // loop over the tabs starting from the current one
+ do {
+ const auto tabPage = tabPageAt(i);
+ if (tabPage->primaryViewContainer()->url().isParentOf(item)) {
+ const KFileItem fileItemContainingItem = tabPage->primaryViewContainer()->view()->items().findByUrl(dirContainingItem);
+ if (!fileItemContainingItem.isNull() && tabPage->primaryViewContainer()->view()->isExpanded(fileItemContainingItem)) {
+ return std::optional(ViewIndex{i, true});
+ }
+ }
+
+ if (tabPage->splitViewEnabled() && tabPage->secondaryViewContainer()->url().isParentOf(item)) {
+ const KFileItem fileItemContainingItem = tabPage->secondaryViewContainer()->view()->items().findByUrl(dirContainingItem);
+ if (!fileItemContainingItem.isNull() && tabPage->secondaryViewContainer()->view()->isExpanded(fileItemContainingItem)) {
+ return std::optional(ViewIndex{i, false});
+ }
+ }
+
+ i = (i + 1) % count();
+ } while (i != currentIndex());
+
+ return std::nullopt;