fix(open): closes #243

This commit is contained in:
Dan Kaplun 2015-12-23 21:05:59 -05:00
parent 708f5ba74c
commit 829b3347b8

View File

@ -53,18 +53,19 @@ Slap.prototype.open = Promise.method(function (filePath, current) {
var self = this;
var pane = self.paneForPath(filePath);
pane = pane || new Pane({parent: self});
if (fs.lstatSync(filePath).isDirectory()) { // check if filePath is a directory
self.fileBrowser.refresh(filePath, _.noop); // open the directory on the sidebar
return;
}
return pane.editor.open(filePath)
return Promise.resolve(pane)
.then(function () {
if (pane) return;
if (fs.lstatSync(filePath).isDirectory()) throw _.merge(new Error('EISDIR: illegal operation on a directory, read'), {cause: {code: 'EISDIR'}});
pane = new Pane({parent: self});
return pane.editor.open(filePath);
})
.then(function () {
if (current) pane.setCurrent();
return pane;
})
.catch(function (err) {
pane.close();
if (pane) pane.close();
switch ((err.cause || err).code) {
case 'EACCES':
self.header.message(err.message, 'error');