mantrajs-atom-package icon indicating copy to clipboard operation
mantrajs-atom-package copied to clipboard

Clicking on a file in matrajs panel opens file twice

Open dtwist opened this issue 9 years ago • 11 comments
trafficstars

First off: Thank you for all the effort thus far. I'm diving in to Atom, Meteor and Mantra all at once, and this package is a boon. :)

Description When I click on a file in the module-specific pane, the file is opened twice in Atom. This doesn't happen in the project-wide pane (methods, pubs & library folders).

Expected The file should only be opened once.

Detail I did a bit of poking around in source and dev tools, and found that the click handler in DirectoryHandler.load() is firing twice. Stopping propagation at the end of that handler does the trick (from a UI perspective), but that feels like a sledgehammer where a scalpel is needed. I've run out of time to keep digging further, and I suspect you'd be able to discern the real issue about 500x faster than me. ;)

Platform: MacOS 10.10.5. Atom Version: 1.5.3 Packages:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

dtwist avatar Feb 29 '16 07:02 dtwist

Sorry for a late reply. I simply cannot reproduce it;( I tested the package now on Windows and Ubuntu and Mac and no issue with double opening. I would try to disable all packages and checking which one does the problem:/

tomitrescak avatar Mar 05 '16 22:03 tomitrescak

But just in case I will add that stop propagation command and test it.

tomitrescak avatar Mar 05 '16 22:03 tomitrescak

I had the same issue on Windows, when clicking on files that are in folders.

Vincent-P avatar Mar 05 '16 22:03 Vincent-P

@tomitrescak Not to worry, looks like you're a busy man these days. :)

I just tested on a fresh user account, current version of Atom and with mantrajs as the only package. Still occurs for me, though I learned more about what triggers it, and that it actually does occur with the methods & pubs folders too:

To reproduce

  1. Create an empty folder and open it as a project folder in Atom.
  2. Toggle the Matrajs tools on. (It will generate the basic skeleton)
  3. Create a new module, foo
  4. Click any file listed under that module.
    [Note: that the file opens once, as expected.]
  5. Create a new component, bar.jsx
  6. Click any file under components.
    [Note: that the file opens twice.]
  7. Create a new component, bar.jsx
  8. Click any file under components.
    [Note: that the file opens thrice.]

    ... add a new component, get four tabs; another, get 5; etc.

The same is true for actions, components, containers, methods and publications. This behavior 'resets' if you disable and re-enable the Mantrajs tools. I suspect a click handler is getting added every time a new component/action/method/publication is created.

Cheers, David

dtwist avatar Mar 06 '16 00:03 dtwist

Yeah stopPropagation fixes it

in /lib/directoryHandler.coffee

$(@container).on 'click', '.list-item[is=tree-view-file]', (e) ->
      DirectoryHandler.revealActiveFile(e)
      e.stopPropagation()
....

Looks like directoryHandler adds new 'click' event listeners each time the treview is refreshed (generated new file or copied manualy outside the editor) So opened tabs count grow up each time you add/remove file from directory. Counter resets when you switch to another module.

Variant below disables previously attached events and reattach new one. stopPropagation on contextmenu disables context menu (without it tabs opened twice)

    $(@container).off 'click', '.list-item[is=tree-view-file]'
    $(@container).on 'click', '.list-item[is=tree-view-file]', (e) ->
        DirectoryHandler.revealActiveFile(e)
        atom.workspace.open(this.file.path)
        this.getPath = () -> return this.file.path # TODO: Check other options
        DirectoryHandler.select(this)
        e.stopPropagation()
        # e.preventDefault()
    $(@container).off 'contextmenu', '.list-item[is=tree-view-file]'
    $(@container).on 'contextmenu', '.list-item[is=tree-view-file]', (e) ->
        atom.workspace.open(this.file.path)
        DirectoryHandler.select(this)
        DirectoryHandler.revealActiveFile(e)
        e.stopPropagation()
        #e.preventDefault()

Finnaly I've commented contextmenu handler so it works in its standart way but without selecting/opening file.

degger80 avatar Mar 29 '16 07:03 degger80

same problem here

PolGuixe avatar Apr 14 '16 15:04 PolGuixe

Guys, I am unable to fix this. It even opens 2-4 times for me, I did what was proposed by @degger80 but that does not seem to fix the issue. Am currently swamped by teaching activities and do not have much time, a PR would be heartfully welcome.

tomitrescak avatar May 01 '16 02:05 tomitrescak

The change suggested by @degger80 seemed to work for me.

mbabauer avatar May 23 '16 02:05 mbabauer

Alright, nevermind. It's still happening to me as well. Seemed to work for a very short while, though.

mbabauer avatar May 24 '16 11:05 mbabauer

Can you update the package? I just released a new version that hopefully solves this issue. At lest I had no problem with it so far.

tomitrescak avatar May 24 '16 12:05 tomitrescak

Awesome! Seems to be working now. I'll let you know if I see any issues moving forward.

mbabauer avatar May 24 '16 13:05 mbabauer