How to access current Tab


#1

I’m showing a view in the main window, that lists specific line numbers. How can I get the current editor view so that I can set the cursor position?


#2

Here’s your answer:

atom.workspace.getActiveEditor() # Returns the active Editor

As for setting the cursor position you can use either the Editor.setCursorScreenPosition or the Editor.setCursorBufferPosition methods.
The former works with the screen coordinates (after wrapping) when the latter works with buffer coordinates (before wrapping).


#3

The problem with this function is that the view I’m showing is going to be the active pane? So isn’t getActiveEditor going to be undefined?


#4

Then you can use atom.workspaceView.getActivePane() to get the active pane or atom.workspaceView.getActiveView() to get the active view, whether it’s an EditorView or something else.