Skip to content

Sort tabs in source edit window #9890

Backlog
Backlog

Description

@dmurdoch

This was already filed a few years ago, as https://community.rstudio.com/t/sort-source-file-tabs-alphabetically-in-ide/5760, but that was closed when #1664 was opened. However, the request to sort tabs alphabetically never made it into 1664. So, I'd like to suggest it again.

The original suggestion would have something like "Sort tabs" on the tab context menu. An alternative way to do it is to add a project option to "keep source files sorted alphabetically". I'd slightly prefer the latter, but either one would be fine.

Activity

  1. ronblum commented on Sep 28, 2021

    @ronblum
    Contributor

    @dmurdoch Thank you for filing the suggestion! We'll review it as we continue development of RStudio.

  2. kuriwaki commented on Oct 24, 2021

    @kuriwaki

    As the author of that original inquiry, I want to thank @dmurdoch for reviving this. I think this is a common enough use case and will also incentivize the tidyverse style guide recommendation of naming scripts 01_, 02_.

  3. github-actions commented on Apr 22, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

  4. added
    stale
    on Apr 22, 2022
  5. github-actions commented on May 7, 2022

    @github-actions

    This issue has been automatically closed due to inactivity.

  6. added this to the 2027.01 milestone on Nov 29, 2026
  7. gtritchie commented on Nov 29, 2026

    @gtritchie
    Member

    Implementation plan

    Add a Sort All Tabs item to the editor tab context menu. It sorts the tabs of every source column, in the main window and in all popped-out (satellite) source windows. Each column is sorted on its own; tabs never move between columns or windows. The name "Sort All Tabs" makes clear that it acts on more than the clicked tab's column.

    Out of scope: the "keep source files sorted" project option. That would mean every open, rename and drag respecting the sort order, which is a much larger change.

    Existing machinery to build on

    • DocTabLayoutPanel.moveTab() (src/gwt/src/org/rstudio/core/client/theme/DocTabLayoutPanel.java) moves a tab's DOM node and fires TabReorderEvent.
    • SourceColumn.onTabReorder() (src/gwt/src/org/rstudio/studio/client/workbench/views/source/SourceColumn.java) handles that event: it updates tabOrder_, sends set_doc_order to the server (so the order survives a session restart), and calls fireDocTabsChanged(). Drag-and-drop and the Move Tab Left/Right/First/Last commands (SourceColumnManager.onMoveTab*) both go through it.
    • setDocOrder in src/cpp/session/modules/SessionSource.cpp already ranks each column's documents 1..n separately, so sorting per column fits the existing model. No backend changes are needed.
    • The tab context menu is built in DocTabLayoutPanel (look for setTabContextMenuHandler).
    • "Close Others" uses CloseAllSourceDocsExceptEvent, a CrossWindowEvent, to reach other windows. EventBus.fireEventToAllSatellites() sends from the main window to the satellites, and EventBus.fireEventToMainWindow() goes the other way.

    Work

    1. Bulk reorder. Don't sort with repeated moveTab() calls: each call sends its own set_doc_order RPC. Add a DocTabLayoutPanel method that rearranges the tab bar into a given order in one pass. Then add SourceColumn.sortTabs(), which computes the sorted order, applies it, rebuilds tabOrder_ to match, sends one set_doc_order, and calls fireDocTabsChanged(). Keep the previously active tab active. The fiddly part is keeping the tab bar's DOM order and tabOrder_ consistent, so mirror what onTabReorder() does.
    2. Sort key. Case-insensitive by tab title (file name), with full path as the tie-breaker for files that share a name. Tabs with no path (Untitled, data viewer, object explorer, etc.) sort by title.
    3. Command. Add a sortAllSourceTabs command (label "Sort All Tabs") to Commands.cmd.xml with a stub in Commands.java, so it's also available from the command palette and can be given a keyboard shortcut. Rebuild to regenerate Commands.cmd.xml.MD5. The context-menu item runs the command and gets an ElementIds constant like the other tab menu items.
    4. Cross-window. Add a CrossWindowEvent (e.g. SortAllSourceTabsEvent). Each window handles it by sorting all of its own columns (SourceColumnManager.getColumnList()). The main window also forwards it to the satellites with fireEventToAllSatellites(). When the command runs in a satellite, it sends the event to the main window, which then sorts and forwards as above.
    5. Tests.
      • GWT unit test for the sort comparator: case-insensitivity, same-name tie-break by path, tabs with no path. Register it in RStudioUnitTestSuite.java.
      • Playwright test under e2e/rstudio/: open files in two source columns plus a popped-out window, run Sort All Tabs, check that each one is sorted, and check that the order survives a reload.
    6. NEWS.md entry under ### New.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsource editorstale

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions