tststs / atom-ternjs

JavaScript code intelligence for atom with tern.js and autocomplete-plus
MIT License
628 stars 76 forks source link

focusEditor() does not work From active Pane Item #384

Open JakeIwen opened 3 years ago

JakeIwen commented 3 years ago

if a non- TextEditor pane is selected, focusEditor() is called via atom.workspace.onDidChangeActivePaneItem( in atom-ternjs-manager.js.

I believe this break happened in Release 0.18.0

see this issue for an example of the problem it causes

Here's my patch in atom-ternjs-helper.js

export function focusEditor() {

 // const editor = atom.workspace.getActiveTextEditor();
 // getActiveTextEditor() will return the last focused textEditor, and re-focus it at the end of this function

  const editor = atom.workspace.getActivePaneItem();
  // Instead use getActivePaneItem() and isValidEditor() to determine editor validity. 

  // if (!editor) { // this condition pretty much never met with getActiveTextEditor()
  if (!isValidEditor(editor)) {

    return;

  }

  const view = atom.views.getView(editor);

  view && view.focus && view.focus();
}