镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[GTK] Navigate Tree rows with Left and Right as on Windows - #3744

Open
anydoby wants to merge 1 commit into
eclipse-platform:masterfrom
anydoby:gtk-tree-arrow-navigation
Open

anydoby wants to merge 1 commit into
eclipse-platform:masterfrom
anydoby:gtk-tree-arrow-navigation

Conversation

@anydoby

@anydoby anydoby commented Oct 18, 2026 •

Copy link
Copy Markdown

On GTK, Left and Right in a Tree only expand and collapse the cursor row when it has children. On a leaf they do nothing. On Windows they also move through the tree, and that is what users coming from Windows expect, for example in the Project Explorer.

This change makes GTK3 and GTK4 navigate the same way:

  • Right expands a collapsed row, and moves to the first child of an expanded row.
  • Left collapses an expanded row, and moves to the parent of any other row.

Keys with modifiers and the keys of the search entry are still left to GtkTreeView. The handling runs after the SWT.KeyDown listeners, so a listener that sets doit = false still stops it. The GTK4 handler from #3694 now uses the same code, and the Left and Right key bindings in swt_functional_gtk_3_20.css are removed, since the Java code replaces them.

macOS differs for Right: an earlier version of this PR had a test for it, and on macOS Right on an expanded item does not move to its first child. Left behaves the same as on macOS.

Testing

  • Sent real X key presses with xdotool to a snippet in a nested X server, on GTK4 4.22.4 and GTK3 3.24.52, with the SWT I20261017-2300 build plus this change: Right and Left through nested items, a lazily populated item (filled in an SWT.Expand listener), the keypad arrows, and Shift+Right. All behave as described above, and SWT.Selection is sent for each cursor move. The unpatched build only expands and collapses.
  • Ran Test_org_eclipse_swt_widgets_Tree on GTK3 / X11 (nested Xephyr): 140 tests pass, including two local Display.post tests for Left and Right that are not part of this PR.
  • Tested an earlier version by hand, applied to SWT 3.135, in Eclipse IDE 2026-09 (4.41.0), build id 20260903-0720, on GTK3 and GTK4, X11.

🤖 Generated with Claude Code

@anydoby
anydoby force-pushed the gtk-tree-arrow-navigation branch from 26ac19c to 0e4feda Compare October 18, 2026 13:44
@anydoby
anydoby marked this pull request as ready for review October 18, 2026 14:20
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 1 013 files   -  4   1 013 suites   - 4   1h 35m 59s ⏱️ + 9m 43s
 5 054 tests  -  3   5 025 ✅  -  4     28 💤 ±0  1 ❌ +1 
29 695 runs   - 12  27 161 ✅  - 14  2 532 💤 ±0  2 ❌ +2 

For more details on these failures, see this check.

Results for commit b7e25f3. ± Comparison against base commit 854e4c1.

This pull request removes 5 and adds 2 tests. Note that renamed tests count towards both.
org.eclipse.swt.tests.cocoa.Test_cocoa_AccessibleTextRanges ‑ test_attributedStringForRange_listenerNotAdvancing
org.eclipse.swt.tests.cocoa.Test_cocoa_AccessibleTextRanges ‑ test_attributedStringForRange_pastEnd
org.eclipse.swt.tests.cocoa.Test_cocoa_AccessibleTextRanges ‑ test_lineForIndex_indexPastEnd
org.eclipse.swt.tests.cocoa.Test_cocoa_AccessibleTextRanges ‑ test_selectedText_selectionPastEnd
org.eclipse.swt.tests.cocoa.Test_cocoa_AccessibleTextRanges ‑ test_stringForRange_pastEnd
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_Tree ‑ test_arrowLeft_movesToParentAndCollapses
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_Tree ‑ test_arrowRight_expandsAndMovesToFirstChild

@akurtakov

Copy link
Copy Markdown
Member

Merge commits are not allowed.

@akurtakov

Copy link
Copy Markdown
Member

Review comments:

  1. Rebase and squash, since the merge commit fails check-merge-commits.
  2. Remove SWTTreeViewBinding from swt_functional_gtk_3_20.css. The new Java code replaces it, and GTK3 behaves the same without it.
  3. The method can be much shorter, without iterators:
boolean navigateWithArrowKey (int keyval, int state) {
        if (keyval != GDK.GDK_Left && keyval != GDK.GDK_KP_Left && keyval != GDK.GDK_Right && keyval != GDK.GDK_KP_Right) return false;
        if ((state & (GDK.GDK_SHIFT_MASK | GDK.GDK_CONTROL_MASK | GDK.GDK_MOD1_MASK | GDK.GDK_SUPER_MASK | GDK.GDK_META_MASK | GDK.GDK_HYPER_MASK)) != 0) return false;
        if (!GTK.gtk_widget_has_focus (handle)) return false;
        long [] path = new long [1];
        GTK.gtk_tree_view_get_cursor (handle, path, null);
        if (path [0] == 0) return false;
        boolean right = (keyval == GDK.GDK_Right || keyval == GDK.GDK_KP_Right) != ((style & SWT.RIGHT_TO_LEFT) != 0);
        boolean expanded = GTK.gtk_tree_view_row_expanded (handle, path [0]);
        boolean handled;
        if (right != expanded) {
                handled = right ? GTK.gtk_tree_view_expand_row (handle, path [0], false) : GTK.gtk_tree_view_collapse_row (handle, path [0]);
        } else {
                if (right) GTK.gtk_tree_path_append_index (path [0], 0);
                handled = right || (GTK.gtk_tree_path_get_depth (path [0]) > 1 && GTK.gtk_tree_path_up (path [0]));
                if (handled) GTK.gtk_tree_view_set_cursor (handle, path [0], 0, false);
        }
        GTK.gtk_tree_path_free (path [0]);
        return handled;
}
  1. Please drop the tests. They're disabled on Jenkins (test_backspaceAndDelete StyledText and Text fail on I-build machine #2571), so they only run in GitHub Actions. I'd rather not add more of these.

GtkTreeView only expands and collapses rows with children for Left and
Right, and does nothing on a leaf. Navigate like the Windows tree
instead, on GTK3 and GTK4:

- Right expands a collapsed row and moves to the first child of an
  expanded row.
- Left collapses an expanded row and moves to the parent of any other
  row.

Keys with modifiers and the keys of the search entry are still left to
GtkTreeView. This replaces the Left and Right key bindings of
swt_functional_gtk_3_20.css.

Assisted-by: Anthropic Claude Code (claude-opus-5-5)
@anydoby
anydoby force-pushed the gtk-tree-arrow-navigation branch from b7e25f3 to e5486e0 Compare October 21, 2026 16:18
@anydoby anydoby changed the title [GTK] Navigate Tree rows with Left and Right as on Windows and macOS [GTK] Navigate Tree rows with Left and Right as on Windows Oct 21, 2026
@anydoby

anydoby commented Oct 21, 2026

Copy link
Copy Markdown
Author

Thanks for the review @akurtakov. Tests are gone now :( I rebased/squashed. Macos test failed since the Right on an expanded item doesn't move to the first child. Actually the way it works on a mac is fine usability-wise. I only had problems with Linux :)
I manually retested on gtk4 and gtk3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants