From 5f1f8757a6cf75840a2bd330bd1e9dfc5f1751bd Mon Sep 17 00:00:00 2001 From: Federico Jeanne Date: Wed, 15 Jul 2026 16:09:47 +0200 Subject: [PATCH] Revert CTabFolder-specific traversal workaround in TraversePageHandler Restores the standard focus-traversal behavior in TraversePageHandler by removing the special-casing that was added for CTabFolder (loop-to-first/ last-item logic, hidden-item detection, and the top-level CTabFolder lookup helpers introduced by #2864 and the earlier fix for #4135). This special-casing was a workaround for CTabFolder not looping over its own tabs when using Ctrl+PageUp/PageDown. That is now fixed directly in SWT's CTabFolder.onPageTraversal (see eclipse-platform/eclipse.platform.swt#3448), which makes this handler's workaround unnecessary and, in some cases, incorrect (e.g. it bypassed the chevron/drop-down list when tabs did not fit). Requires eclipse-platform/eclipse.platform.swt#3448 to be merged/available for the circular navigation behavior to still work correctly. Fixes #4135 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../handlers/TraversePageHandler.java | 67 +------------------ 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java index a8435c3dce1..67644bc5d38 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/handlers/TraversePageHandler.java @@ -13,11 +13,8 @@ *******************************************************************************/ package org.eclipse.ui.internal.handlers; import java.lang.reflect.Method; -import java.util.Arrays; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CTabFolder; -import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -38,16 +35,9 @@ public final Object execute(final ExecutionEvent event) { Control focusControl = Display.getCurrent().getFocusControl(); if (focusControl != null) { boolean forward = "next".equals(methodName); //$NON-NLS-1$ - int traversalDirection = translateToTraversalDirection(forward); + final int traversalDirection = translateToTraversalDirection(forward); Control control = focusControl; do { - if (control instanceof CTabFolder) { - CTabFolder folder = getTopLevelCTabFolderInParentHierarchy(control); - if (isFinalItemInCTabFolder(folder, forward) && !hasHiddenItem(folder)) { - loopToFirstOrLastItem(folder, forward); - traversalDirection = translateToTraversalDirection(!forward); - } - } if (control.traverse(traversalDirection)) { return null; } @@ -60,65 +50,10 @@ public final Object execute(final ExecutionEvent event) { return null; } - /** - * @param c a {@code Control}. - * @return the top-level {@code CTabFolder} in the parent hierarchy. - */ - private CTabFolder getTopLevelCTabFolderInParentHierarchy(Control c) { - Control current = c; - CTabFolder ret = null; - do { - if (current instanceof CTabFolder folder) { - ret = folder; - } - current = current.getParent(); - } while (current != null); - return ret; - } - - private boolean hasHiddenItem(CTabFolder folder) { - return Arrays.stream(folder.getItems()).anyMatch(i -> !i.isShowing()); - } - private int translateToTraversalDirection(boolean forward) { return forward ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; } - /** - * Sets the current selection to the first or last item the given direction. - * - * @param folder the CTabFolder which we want to inspect - * @param forward whether we want to traverse forwards of backwards - */ - private void loopToFirstOrLastItem(CTabFolder folder, boolean forward) { - if (forward) { - folder.showItem(folder.getItem(0)); - folder.setSelection(1); - } else { - int itemCount = folder.getItemCount(); - folder.setSelection(itemCount - 2); - } - } - - /** - * {@return Returns whether the folder has currently selected the final item in - * the given direction.} - * - * @param folder the CTabFolder which we want to inspect - * @param forward whether we want to traverse forwards of backwards - */ - private boolean isFinalItemInCTabFolder(CTabFolder folder, boolean forward) { - CTabItem currentFolder = folder.getSelection(); - CTabItem lastFolder = null; - if (forward) { - int itemCount = folder.getItemCount(); - lastFolder = folder.getItem(itemCount - 1); - } else { - lastFolder = folder.getItem(0); - } - return currentFolder.equals(lastFolder); - } - /** * Looks up the traverse(int) method on the given focus control. *