ahuth / preview-tabs

Sublime-style preview tabs for Atom
MIT License
11 stars 2 forks source link

preview-tabs-preview not being added #14

Open michael-jerred opened 9 years ago

michael-jerred commented 9 years ago

When I single-click a file to preview it, the 'preview-tabs-preview' class doesn't get added to the DOM element. For reference I'm using Windows, with Atom v0.155.0

It looks like this is happening because at the time when PreviewTabsPaneController._onPaneItemAdded is called, the new tab has not been added to the DOM yet, so the method _findTabForEditor doesn't manage to obtain the tab to add the class to:

_findTabForEditor: (editor) ->
  path = editor.getPath()
  @paneView.find(".tab [data-path='#{path}']")

I'm not sure how to fix this.

ahuth commented 9 years ago

Thanks for submitting this issue, and for digging into the code to see where the problem is!

And you're exactly right: when _onPaneItemAdded is called, the tab is not in the DOM, yet.

One way to fix this that works is to put the call to _findTabForEditor in an underscore defer call (which basically just puts the call into a setTimeout). When it runs, the tab is in the DOM. I'm also trying to see if there's another event I can subscribe to that prevent us from having to do that.

Thanks again for catching this.