Skip to content

Commit 3b7d70e

Browse files
fedejeanneChristopher-HermannBeckerWdf
committed
Fix traversal of CTabFolders with PgUp/PgDown #2864
When traversing from an editor with tabs (e.g. a POM or MANIFEST editor), which is a CTabFolder itself, I made sure that the traversal happens from the top-level CTabFolder i.e. from the one that contains all open editors instead of trying to traverse inside the editor itself. Fixes #2864 Co-authored-by: Christopher Hermann <christopher.hermann@sap.com> Co-authored-by: Matthias Becker <ma.becker@sap.com>
1 parent 29f3a4f commit 3b7d70e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ public final Object execute(final ExecutionEvent event) {
4141
int traversalDirection = translateToTraversalDirection(forward);
4242
Control control = focusControl;
4343
do {
44-
if (control instanceof CTabFolder folder && isFinalItemInCTabFolder(folder, forward)
45-
&& !hasHiddenItem(folder)) {
46-
loopToFirstOrLastItem(folder, forward);
47-
traversalDirection = translateToTraversalDirection(!forward); // we are in the second-to-last item in the given
48-
// direction. Now, use the Traverse-event to move back by one
44+
if (control instanceof CTabFolder) {
45+
CTabFolder folder = getTopLevelCTabFolderInParentHierarchy(control);
46+
if (isFinalItemInCTabFolder(folder, forward) && !hasHiddenItem(folder)) {
47+
loopToFirstOrLastItem(folder, forward);
48+
traversalDirection = translateToTraversalDirection(!forward);
49+
}
4950
}
5051
if (control.traverse(traversalDirection)) {
5152
return null;
@@ -59,6 +60,22 @@ public final Object execute(final ExecutionEvent event) {
5960
return null;
6061
}
6162

63+
/**
64+
* @param c a {@code Control}.
65+
* @return the top-level {@code CTabFolder} in the parent hierarchy.
66+
*/
67+
private CTabFolder getTopLevelCTabFolderInParentHierarchy(Control c) {
68+
Control current = c;
69+
CTabFolder ret = null;
70+
do {
71+
if (current instanceof CTabFolder folder) {
72+
ret = folder;
73+
}
74+
current = current.getParent();
75+
} while (current != null);
76+
return ret;
77+
}
78+
6279
private boolean hasHiddenItem(CTabFolder folder) {
6380
return Arrays.stream(folder.getItems()).anyMatch(i -> !i.isShowing());
6481
}

0 commit comments

Comments
 (0)