Skip to content

Commit adb2a2e

Browse files
Fix traverse in multi page editors
control.traverse on a CTabFolder in the MultiPageEditor is navigation up the the outer CTabFolder itself. This is causing several issues: Setting the page for example to the second-to-last is changing the page in the multipage editor. Then the traverse direction is changed causing the outer tab to move in the wrong direction. Furthermore on the outer tab you cannot jump from the last tab to the very first tab.
1 parent a3fa065 commit adb2a2e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public final Object execute(final ExecutionEvent event) {
4141
int traversalDirection = translateToTraversalDirection(forward);
4242
Control control = focusControl;
4343
do {
44+
if (control instanceof CTabFolder folder && !isRootCTabFolder(folder)) {
45+
// For multi-page editors, we want to skip inner CTabFolders
46+
// If not skipped there are two issues:
47+
// 1. loopToFirstOrLastItem would change the selection of the inner CTabFolder
48+
// 2. control.traverse itself would navigate up to the outer CTabFolder and
49+
// navigate there
50+
control = control.getParent();
51+
continue;
52+
}
4453
if (control instanceof CTabFolder folder && isFinalItemInCTabFolder(folder, forward)
4554
&& !hasHiddenItem(folder)) {
4655
loopToFirstOrLastItem(folder, forward);
@@ -59,6 +68,15 @@ public final Object execute(final ExecutionEvent event) {
5968
return null;
6069
}
6170

71+
private boolean isRootCTabFolder(CTabFolder folder) {
72+
for (var current = folder.getParent(); current != null; current = current.getParent()) {
73+
if (current instanceof CTabFolder) {
74+
return false;
75+
}
76+
}
77+
return true;
78+
}
79+
6280
private boolean hasHiddenItem(CTabFolder folder) {
6381
return Arrays.stream(folder.getItems()).anyMatch(i -> !i.isShowing());
6482
}

0 commit comments

Comments
 (0)