mantrajs-atom-package
mantrajs-atom-package copied to clipboard
Clicking on a file in matrajs panel opens file twice
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]
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:/
But just in case I will add that stop propagation command and test it.
I had the same issue on Windows, when clicking on files that are in folders.
@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
- Create an empty folder and open it as a project folder in Atom.
- Toggle the Matrajs tools on. (It will generate the basic skeleton)
- Create a new module, foo
- Click any file listed under that module.
[Note: that the file opens once, as expected.] - Create a new component, bar.jsx
- Click any file under components.
[Note: that the file opens twice.] - Create a new component, bar.jsx
- 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
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.
same problem here
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.
The change suggested by @degger80 seemed to work for me.
Alright, nevermind. It's still happening to me as well. Seemed to work for a very short while, though.
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.
Awesome! Seems to be working now. I'll let you know if I see any issues moving forward.