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

Fix #5537: Start live development even if there is no open file #5547

Merged
merged 3 commits into from
Oct 24, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by, after-the-fact comment: CollectionUtils.indexOf is deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there before ;) Not my fault


// 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