adobe/brackets — pull request #2198 by jbalsas (2012-11-23 00:46:05+00:00)
Title: Create files on collapsed folders (#2085)

This is a possible fix for #2085 by waiting on the `open_node.jstree` event before trying to create a new node.

It looks like we're hitting a strange race condition in `jsquery.jstree.js` which appears when the node we want to open hasn't been loaded yet.

In that case, `open_node` triggers a `load_node` in line 640.

```javascript
632	open_node	: function (obj, callback, skip_animation) {
[...]
638	if(!this._is_loaded(obj)) {
639	obj.children("a").addClass("jstree-loading");
640	this.load_node(obj, function () { t.open_node(obj, callback, skip_animation); }, callback);
641	}
```

Almost at the same time, a different `load_node` is triggered from the CRRM `create` through `create_node` in line 734
```javascript
726	create_node	: function (obj, position, js, callback, is_loaded) {
[...]
733	if(obj !== -1 && !obj.length) { return false; }
734	if(!is_loaded && !this._is_loaded(obj)) { this.load_node(obj, function () { this.create_node(obj, position, js, callback, true); }); return false; }
735
736	this.__rollback();
```

Not digging much further, if the second `load_node` gets called because the first one is not completed, then `create_node` is not called again as expected and nothing gets created. This can be tested by adding a breakpoint in line 733. Doing that, the first `load_node` always finishes and the function completes ok.

By waiting to the `open_node` event, we're making sure we always step into `create_node` once the node is already loaded.