How to programmatically switch to a specific tab


#1

Hi,

I’m learning CoffeeScript and how to make Atom packages at the same time. I’m trying to make a simple package that allows to navigate between cursor positions. For instance, I go to a definition of a symbol, scroll a little, move the cursor around and want to go back to the last place I browsed before.

Right now, I successfully keep cursor position history and navigate to past positions in the same file, but I can’t figure out how to go back to another opened file. I tried figuring it out first from documentation, then by searching through the packages on Github and finally by trial and error, but I’m not even sure what to search for… Editor? EditorView? Pane? Tab?..

Can someone point me to the right direction?

Thanks


#2

This seems to work

{$} = require 'atom'
tabPosition = 2
$("ul.tab-bar li.tab:nth-child(#{tabPosition})")[0].click()

#3

Each “file” has an Editor. The set of open editors live in a Pane. You can get the main pane with:

pane = atom.workspace.getActivePane()

Check the Pane docs to see how you can get and rearrange the items in a pane. Usually an item is an editor, but there’s also stuff like settings, which aren’t.

Hope this helps.


#4

Thanks for the clarifications.

I could not find a way to directly activate an editor I already had, but I managed to achieve what I wanted to do by repeatedly calling Pane::activateNextItem() and testing the active one again with atom.workspace.getActivePane() until I get the right one (if it still exists).

With that, I should be able to publish my package ( … boy that sounded weird :S ) soon!