How to open a tab in the background?



I would like my package to open a tab in the background. From the API, I expected I needed to do: "path/to/file", {activateItem: false})

But doing this won’t open the file at all! Am I doing something wrong, or should I file a bug report?

Using atom v1.13.


You’re not doing anything wrong necessarily. You’re misunderstanding what activateItem does. The file is open. If you get the value from the resolved Promise there is a TextEditor created. You can even pass that TextEditor object to Pane.activateItem and it will be displayed. It’s just that Atom doesn’t have the concept of “open an item behind other items”. Either you want to open something and display it (on top of everything else) or you don’t want to display it.


Ok gotcha.

So here’s how I did it in the end, for anyone else’s future reference:

myPane = atom.workspace.getActivePane()
myPaneItem = atom.workspace.getActivePaneItem() "path/to/file"
     .then () ->
         # Must find index after open, since it may have changed
         myPaneItemIndex = myPane.getItems().findIndex(
             (item) -> item == myPaneItem )
         myPane.activateItemAtIndex myPaneItemIndex

This is possible since returns a promise. Just activating myPaneItem after the call to open won’t work since the open call is asynchronous (so you would be activating myPaneItem before open is finished).