You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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_.
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
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.
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.
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.
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.
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.
Activity
ronblum commentedon Sep 28, 2021
@dmurdoch Thank you for filing the suggestion! We'll review it as we continue development of RStudio.
kuriwaki commentedon Oct 24, 2021
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_.
github-actions commentedon Apr 22, 2022
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.
github-actions commentedon May 7, 2022
This issue has been automatically closed due to inactivity.
gtritchie commentedon Nov 29, 2026
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 firesTabReorderEvent.SourceColumn.onTabReorder()(src/gwt/src/org/rstudio/studio/client/workbench/views/source/SourceColumn.java) handles that event: it updatestabOrder_, sendsset_doc_orderto the server (so the order survives a session restart), and callsfireDocTabsChanged(). Drag-and-drop and the Move Tab Left/Right/First/Last commands (SourceColumnManager.onMoveTab*) both go through it.setDocOrderinsrc/cpp/session/modules/SessionSource.cppalready ranks each column's documents 1..n separately, so sorting per column fits the existing model. No backend changes are needed.DocTabLayoutPanel(look forsetTabContextMenuHandler).CloseAllSourceDocsExceptEvent, aCrossWindowEvent, to reach other windows.EventBus.fireEventToAllSatellites()sends from the main window to the satellites, andEventBus.fireEventToMainWindow()goes the other way.Work
moveTab()calls: each call sends its ownset_doc_orderRPC. Add aDocTabLayoutPanelmethod that rearranges the tab bar into a given order in one pass. Then addSourceColumn.sortTabs(), which computes the sorted order, applies it, rebuildstabOrder_to match, sends oneset_doc_order, and callsfireDocTabsChanged(). Keep the previously active tab active. The fiddly part is keeping the tab bar's DOM order andtabOrder_consistent, so mirror whatonTabReorder()does.sortAllSourceTabscommand (label "Sort All Tabs") toCommands.cmd.xmlwith a stub inCommands.java, so it's also available from the command palette and can be given a keyboard shortcut. Rebuild to regenerateCommands.cmd.xml.MD5. The context-menu item runs the command and gets anElementIdsconstant like the other tab menu items.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 withfireEventToAllSatellites(). When the command runs in a satellite, it sends the event to the main window, which then sorts and forwards as above.RStudioUnitTestSuite.java.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.### New.