How do you use the new "Document Tabs" feature?

Xcode 12 introduces a new way to manage tabs as "Document Tabs" that, presumably, works similar to how other editors like VSCode handle tabs (i.e. an editor tab belongs to a specific document and doesn't change if you CMD+Click on something else)

I somehow activated this once while clicking around but I'm not sure how I did it and I don't see it mentioned in the preferences or shortcuts.

Anyone know how this feature works?
Answered by Developer Tools Engineer in 613745022
Sure, the basics are:
  • - If you OPTION+CLICK on an item in the File Navigator, that will open up a new document tab.
  • If you double-click a dynamic tab, it will become a static tab.

  • Open Quickly (CMD+SHIFT+O) will open up a file into your dynamic tab.

  • From View->Always Show Tab Bar, Xcode will always show the document tabs, even if there is only one.

You can also re-order the tabs and use them with split editors as well.
Accepted Answer
Sure, the basics are:
  • - If you OPTION+CLICK on an item in the File Navigator, that will open up a new document tab.
  • If you double-click a dynamic tab, it will become a static tab.

  • Open Quickly (CMD+SHIFT+O) will open up a file into your dynamic tab.

  • From View->Always Show Tab Bar, Xcode will always show the document tabs, even if there is only one.

You can also re-order the tabs and use them with split editors as well.
Thanks for the help!

Some feedback:
  1. I'm not sure if "Document Tab" is the official name of these or not. That's what they're called in the "Introducing Xcode 12" page but I don't see them called that in Xcode itself.

  2. It would be nice if there was a visual difference between a regular tab and a tab that contains document tabs? In fact the whole notion that a Document Tab is a tab and it contains tabs.

and finally:

3. I would like to make the whole thing always use document tabs. i.e. One tab per file unless I choose to open a duplicate tab. I can't tell you how many times I've accidentally had 5 tabs open to the same file and no tabs open to the file I had been recently working on.
I guess I can't edit my own post?

Meant to say:


the whole notion that a Document Tab is a tab and it contains tabs is confusing

This is confusing. Now the original static tab cannot be navigated with CMD+SHIFT+{.

I can create new static tab with CMD+T, but CMD+W will close these document/dynamic tab.

Is there a shortcut for navigating the static tabs?
Ctrl + Tab is used for passing between "window tab bar" tabs.
If this feature is not present, open it via "View->Show window Tab Bar".

Besides, you can use "document tabs" which seems a new & nice feature of Xcode. You can see their default shortcuts via "Navigate -> Show Previous Tab" or "Navigate -> Show Next Tab" or find them on the "Key Binding" tab under "Xcode ->Preferences window"

There are many default shortcuts and I do not want them to change. I am using Turkish keyboard and default shortcuts are not useful. In short, I generally choose Turkish (/your native language) letters for shortcuts. No conflict, no headache. I suggest similar use.
Through experimentation (rather than documentation) I've figured out how to work with the new Documents tabs in Xcode 12. I'm not sure what I think of this yet, but here is how they work:

In the Xcode 12 Navigator, you can either single click on a file or double click on a file, to cause it to open as a Documents tab.

However, if you double-clicked to open a file in a Documents tab, then the next time you try this, for a different file that is not already represented in a Documents tab, it will open in a new Documents tab, rather than replacing the file in the currently selected tab.

To see how this works, try the following:
  1. Open an Xcode project and close any Document tabs that may open by default in result of where you left off with your last session.

  2. Now single click on a file in the Navigator - it will open in a Documents tab.

  3. Now in the Navigator, randomly single click one file after another; you will see each successively replace the preceding in the same Documents tab.

  4. Now in the Navigator, double click on a file to open it. It will also replace the last one you opened. But then the next file that you single click or double click, will open in a new Documents tab.

Also note that:
A. When you single click a file to open it, it's tab will be displayed with an italics font, while if you double click, it will be displayed with a normal font. Think of italics as representing the file as "temporary" and normal as representing the file as "static".
B. If a file was opened with a single click, and it is displayed with an italics font, if you double click on it's name in the Navigator, it will switch to a normal font, switching from "temporary" to "static" status.
C. I am not aware on the other hand, of how to switch a tab back from "static" to "temporary" - this may not be possible?
D. If you have multiple Document tabs open, and you have selected a particular "static" tab, then if you select a new file in the Navigator (that is not already represented in any tab), it will be opened in a new tab, immediately following the currently selected tab, rather than at the end of the tabs.
E. Is it possible to have multiple "temporary" tabs open? No it isn't. And let's say you have 2 "static" tabs open, and you select the first, then open a new "temporary" tab, so that you now have a "static", a "temporary", then another "static". Now if you select the last tab (the second "static"), and in the Navigator you click on another file to open a new "temporary" tab, not only will it appear last, but your preceding "temporary" tab will close.
F. If you tend to open files not by selecting them in the Navigator, but instead by using command+shift+o, at least on first glance, it appears that it is only possible to open files as "temporary".

Assuming "static tabs" refers to the window tabs (that's the term Xcode uses), yes, you can navigate between them using keyboard shortcuts. Search for "Show Next Window Tab" and "Show Previous Window Tab" in the key bindings. There, you can set your own keyboard shortcut.
Clarification: Xcode now supports both "Window" tabs as it long has, and now also "Document" Tabs within Window tabs. Document tabs can be either "static" or "temporary" at least as I described them in my previous post; Window tabs and static tabs are not the same thing, as a subsequent post suggests, at least as per my personal choice of terminology (at least in my reading of it, Xcode's documentation doesn't distinguish clearly between "Window" and "Document" tabs, let alone properly distinguish the two state possibilities for a Document tab, which I referred to as "static" or "temporary"... Somewhere else on the internet, I picked up on someone else using the terms "static" and "temporary" and thought this sensible).

One more point regarding when and why to use both Window and Document tabs in combination; I'm finding it valuable to use them to separate Document tabs by type. For instance, if working on a SceneKit project:
  • within one Window tab have multiple .swift files in different Document tabs

  • within a second Window tab have multiple .scn files in different Document tabs

  • within a third Window tab have one or more .xcassets files in different Document tabs

  • etc.

grb2007's answer is immensely helpful. However, I still have some confusion here: If I OPTION+CLICK on an item in the File Navigator, that does not open up a new document tab as Developer Tools Engineer  suggests but rather opens a new editor at the bottom of the same temporary (italicised) tab.

There are several references here to the Xcode documentation for this feature. Can anyone provide a link please because I can't find it.
Is there any keyboard shortcut top open a document tab statically instead of dynamically? Or alternatively to convert a dynamic document tab to a static one (other than editing the file and then undoing the edits)?

Using the term "windows" for the top tab like items, and "tabs" are those under each window - I can see a rational as grb2007 mentions for grouping related items.

But this was already possible by having an actual movable "window", with multiple tabs (which are now called "windows"). We have all used that function for years.

My biggest issue is that swiping between tabs seems to be broken. If I click on file1 in the navigator, it shows up. If I click another file2, it shows up. But swiping to the right doesn't show file1, but somewhere else. What's worse, is my file1 shows up for a second, then it's yanked away and that somewhere else shows up. I assume it's using the tab history, but I can't figure it out.

Anyone know how to either remove the new "tab" feature, or at least fix the swiping between files in the file history?

thanks.

Here's my attempt to answer dogcoder's issue (3rd paragraph):

Like grb2007, I've found out the following through experimentation rather than through Apple's Xcode documentation, though I tried hard to go that route.

If you open a project and close all the document (not window) tabs, to start fresh, then open a file in the project navigator, a temporary document tab is opened. Ignoring the tabs for a moment, if you click a couple more files in the project navigator, their contents will be displayed in the editor window. After doing that a few times, you'll find that swiping left or right works as you expected. It will go back and forth between the files you opened in the order that you opened them.

However, the more valuable use of swiping left and right, which matches the behavior of clicking the back and forward buttons in the document tab bar, is to do a manual "stack trace" through your functions and methods.

If you're examining a function's code and it calls another function, you can Cmd-Cntrl-click that second function's name to immediately open its file with it's declaration selected. As you go through its code, you Cmd-Cntrl-click a function it calls to move deeper into the logic. Again, that function's file will open with it selected. Let's say you repeat that sequence three or four more times. Now you're pretty deep in the calling sequence but how do you get back? The incredibly valuable answer is either the back button or swiping. Each back button click (or swipe right) will take you back to the calling function, so you can very conveniently move right back up the calling stack.

This approach includes clicks on any symbol, as far as I can tell, so you can use it to examine type and named value (let or var) declarations as well as function declarations and find your way back up to the top of the reference "stack" when you're done. Of course, if you go half way back up, then click the forward button (or swipe left), you'll retrace your steps back down the stack.

As you'd expect, if you go half way back up, then Cmd-Cntrl-click another symbol, the original stack below you will be lost and replaced by this new reference. Of course, this works whether the symbol you clicked was in another file or the same file you were already in. In either case, your editor window will display the referenced symbol's definition which will be added to the stack. This means that sometimes when you go back up the "stack trace", you will move within a file rather than opening a new file in the editor.

I just discovered this yesterday and haven't yet experimented with the relationship between these clicks and the document tabs but I thought this might be helpful for some.

I'd like to add a couple caveats to my previous post.

First, if you Cmd-Cntrl-click on a symbol, the editor will take you to the declaration of that symbol, as I said above. However, once you've Cmd-Cntrl-clicked on a symbol and it's declaration is displayed in the editor, you can scroll around in the editor. Wherever you scroll to will be the location displayed when going back to that symbol's place in the reference stack, whether the symbol you clicked on is shown in the window or not.

Second, it seems that Cmd-Cntrl-clicking will attempt to select any static tabs that have already been established for the newly opened file. However, if the file doesn't have any static tabs referencing it, a new temporary tab will be created and any subsequent Cmd-Cntrl-clicks on symbols in other files for which there are no static tabs will replace the file in the newly created temporary tab.

Again, I haven't exhaustively tested this, so I'm open to any corrections that others find in this behavior.

How do you use the new "Document Tabs" feature?
 
 
Q