Focus for View


In my package I create an instance of a class that extends View from atom-space-pen-views in a new pane. I can click in the pane and my View gets focus just fine. When I try to switch to the View using something like View->Panes->Focus Pane Below it doesn’t work (get focus).

I am calling atom.workspace.onDidChangeActivePane and I can see the events and detect when the pane containing my View is active, but I don’t know how to generate the equivalent to a click event to force my View to get focus.

Any suggestions?


I think you can use the focus method of the view, i.e. view.focus()


Originally only interactive elements can get the focus (input, textarea, select, etc.). For an arbitrary node to get the focus it must defines a tabindex attribute (use -1 if you don’t want it be accessible using the tab, a positive value will specify its order in the tabbing sequence).