Is There An Event Triggered When Tabs Are Changed / Active Editor Changes


#1

In developing the go-plus package, I would like to ensure that when a user switches tabs or changes the active editor that I hide the errors pane we display if a gofmt or go vet error is identified.

I’d like to attach some behavior to this event to reset the state of the plugin: https://github.com/joefitzgerald/go-plus/pull/6/files#diff-40149ac6ed76c7b6eede525fde612056R27

Does such an event exist, or do you know of any creative ways for me to simulate this behavior?


#2

Looks like Event to focus and unfocus to a tab (EditorView)? might offer some insight into this. Of note, the event mentioned is not documented here: https://atom.io/docs/api/v0.73.0/api/classes/WorkspaceView.html or the View docs.

Docs feature enhancement?


#3

It is common feedback that the documentation does not yet include comprehensive listings of events or properties. If you have detailed feedback for how the Atom team can make writing packages easier, you can add it here:


#4

Here is an “unofficial” list of events https://gist.github.com/ardcore/9262498

What you can do for now (until the documentation gets better) is search for an event on GitHub and see if any of the official packages use it and take that as an example.

Search query: active-pane-item-changed user:atom


#5

We now have : https://atom.io/docs/api/v0.178.0/Workspace#instance-onDidChangeActivePaneItem

It works but I am being super defensive in making sure the pane is an editor though in my code.


function onDiskAndTs(editor) {
    if (editor && editor.getPath && typeof editor.getPath == "function") {
        var filePath = editor.getPath();
        var ext = path.extname(filePath);
        if (ext == '.ts') {
            if (fs.existsSync(filePath)) {
                return true;
            }
        }
    }
    return false;
}

#6

You could also do …

{TextEditor} = require ‘atom’

if editor instanceof TextEditor then blah blah blah


#7

I found a way:

atom.workspace.observeActivePaneItem (item) ->
    console.log 'how are you'
    ... do your staff here ...

when you switch tab, your code will be triggered

it works for Atom 1.2.4, hehe