Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5547 from SAPlayer/find-index-no-open-file
Browse files Browse the repository at this point in the history
Fix #5537: Start live development even if there is no open file
  • Loading branch information
ingorichter committed Oct 24, 2013
2 parents 8b534ef + 73b25b4 commit 84a5f61
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,57 +674,61 @@ define(function LiveDevelopment(require, exports, module) {
hasOwnServerForLiveDevelopment = (baseUrl && baseUrl.length);

FileIndexManager.getFileInfoList("all").done(function (allFiles) {
var projectRoot = ProjectManager.getProjectRoot().fullPath,
containingFolder,
indexFileFound = false,
stillInProjectTree = true;

if (refPath) {
var projectRoot = ProjectManager.getProjectRoot().fullPath,
containingFolder = FileUtils.getDirectoryPath(refPath),
indexFileFound = false,
stillInProjectTree = true;

var filteredFiltered = allFiles.filter(function (item) {
var parent = getParentFolder(item.fullPath);

return (containingFolder.indexOf(parent) === 0);
});
containingFolder = FileUtils.getDirectoryPath(refPath);
} else {
containingFolder = projectRoot;
}

var filteredFiltered = allFiles.filter(function (item) {
var parent = getParentFolder(item.fullPath);

var filterIndexFile = function (fileInfo) {
if (fileInfo.fullPath.indexOf(containingFolder) === 0) {
if (getFilenameWithoutExtension(fileInfo.name) === "index") {
if (hasOwnServerForLiveDevelopment) {
if ((FileUtils.isServerHtmlFileExt(fileInfo.name)) ||
(FileUtils.isStaticHtmlFileExt(fileInfo.name))) {
return true;
}
} else if (FileUtils.isStaticHtmlFileExt(fileInfo.name)) {
return (containingFolder.indexOf(parent) === 0);
});

var filterIndexFile = function (fileInfo) {
if (fileInfo.fullPath.indexOf(containingFolder) === 0) {
if (getFilenameWithoutExtension(fileInfo.name) === "index") {
if (hasOwnServerForLiveDevelopment) {
if ((FileUtils.isServerHtmlFileExt(fileInfo.name)) ||
(FileUtils.isStaticHtmlFileExt(fileInfo.name))) {
return true;
}
} else {
return false;
}
}
};

while (!indexFileFound && stillInProjectTree) {
i = CollectionUtils.indexOf(filteredFiltered, filterIndexFile);

// We found no good match
if (i === -1) {
// traverse the directory tree up one level
containingFolder = getParentFolder(containingFolder);
// Are we still inside the project?
if (containingFolder.indexOf(projectRoot) === -1) {
stillInProjectTree = false;
} else if (FileUtils.isStaticHtmlFileExt(fileInfo.name)) {
return true;
}
} else {
indexFileFound = true;
return false;
}
}

if (i !== -1) {
DocumentManager.getDocumentForPath(filteredFiltered[i].fullPath).then(result.resolve, result.resolve);
return;
};

while (!indexFileFound && stillInProjectTree) {
i = CollectionUtils.indexOf(filteredFiltered, filterIndexFile);

// We found no good match
if (i === -1) {
// traverse the directory tree up one level
containingFolder = getParentFolder(containingFolder);
// Are we still inside the project?
if (containingFolder.indexOf(projectRoot) === -1) {
stillInProjectTree = false;
}
} else {
indexFileFound = true;
}
}

if (i !== -1) {
DocumentManager.getDocumentForPath(filteredFiltered[i].fullPath).then(result.resolve, result.resolve);
return;
}

result.resolve(null);
});

Expand Down Expand Up @@ -1163,10 +1167,16 @@ define(function LiveDevelopment(require, exports, module) {
// TODO: need to run _onDocumentChange() after load if doc != currentDocument here? Maybe not, since activeEditorChange
// doesn't trigger it, while inline editors can still cause edits in doc other than currentDoc...
_getInitialDocFromCurrent().done(function (doc) {
var prepareServerPromise = (doc && _prepareServer(doc)) || new $.Deferred().reject();
var prepareServerPromise = (doc && _prepareServer(doc)) || new $.Deferred().reject(),
otherDocumentsInWorkingFiles;

if (doc && !doc._masterEditor) {
otherDocumentsInWorkingFiles = DocumentManager.getWorkingSet().length;
DocumentManager.addToWorkingSet(doc.file);

if (!otherDocumentsInWorkingFiles) {
DocumentManager.setCurrentDocument(doc);
}
}

// wait for server (StaticServer, Base URL or file:)
Expand Down

0 comments on commit 84a5f61

Please sign in to comment.