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

Commit 84a5f61

Browse files
committed
Merge pull request #5547 from SAPlayer/find-index-no-open-file
Fix #5537: Start live development even if there is no open file
2 parents 8b534ef + 73b25b4 commit 84a5f61

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed

src/LiveDevelopment/LiveDevelopment.js

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -674,57 +674,61 @@ define(function LiveDevelopment(require, exports, module) {
674674
hasOwnServerForLiveDevelopment = (baseUrl && baseUrl.length);
675675

676676
FileIndexManager.getFileInfoList("all").done(function (allFiles) {
677+
var projectRoot = ProjectManager.getProjectRoot().fullPath,
678+
containingFolder,
679+
indexFileFound = false,
680+
stillInProjectTree = true;
681+
677682
if (refPath) {
678-
var projectRoot = ProjectManager.getProjectRoot().fullPath,
679-
containingFolder = FileUtils.getDirectoryPath(refPath),
680-
indexFileFound = false,
681-
stillInProjectTree = true;
682-
683-
var filteredFiltered = allFiles.filter(function (item) {
684-
var parent = getParentFolder(item.fullPath);
685-
686-
return (containingFolder.indexOf(parent) === 0);
687-
});
683+
containingFolder = FileUtils.getDirectoryPath(refPath);
684+
} else {
685+
containingFolder = projectRoot;
686+
}
687+
688+
var filteredFiltered = allFiles.filter(function (item) {
689+
var parent = getParentFolder(item.fullPath);
688690

689-
var filterIndexFile = function (fileInfo) {
690-
if (fileInfo.fullPath.indexOf(containingFolder) === 0) {
691-
if (getFilenameWithoutExtension(fileInfo.name) === "index") {
692-
if (hasOwnServerForLiveDevelopment) {
693-
if ((FileUtils.isServerHtmlFileExt(fileInfo.name)) ||
694-
(FileUtils.isStaticHtmlFileExt(fileInfo.name))) {
695-
return true;
696-
}
697-
} else if (FileUtils.isStaticHtmlFileExt(fileInfo.name)) {
691+
return (containingFolder.indexOf(parent) === 0);
692+
});
693+
694+
var filterIndexFile = function (fileInfo) {
695+
if (fileInfo.fullPath.indexOf(containingFolder) === 0) {
696+
if (getFilenameWithoutExtension(fileInfo.name) === "index") {
697+
if (hasOwnServerForLiveDevelopment) {
698+
if ((FileUtils.isServerHtmlFileExt(fileInfo.name)) ||
699+
(FileUtils.isStaticHtmlFileExt(fileInfo.name))) {
698700
return true;
699701
}
700-
} else {
701-
return false;
702-
}
703-
}
704-
};
705-
706-
while (!indexFileFound && stillInProjectTree) {
707-
i = CollectionUtils.indexOf(filteredFiltered, filterIndexFile);
708-
709-
// We found no good match
710-
if (i === -1) {
711-
// traverse the directory tree up one level
712-
containingFolder = getParentFolder(containingFolder);
713-
// Are we still inside the project?
714-
if (containingFolder.indexOf(projectRoot) === -1) {
715-
stillInProjectTree = false;
702+
} else if (FileUtils.isStaticHtmlFileExt(fileInfo.name)) {
703+
return true;
716704
}
717705
} else {
718-
indexFileFound = true;
706+
return false;
719707
}
720708
}
721-
722-
if (i !== -1) {
723-
DocumentManager.getDocumentForPath(filteredFiltered[i].fullPath).then(result.resolve, result.resolve);
724-
return;
709+
};
710+
711+
while (!indexFileFound && stillInProjectTree) {
712+
i = CollectionUtils.indexOf(filteredFiltered, filterIndexFile);
713+
714+
// We found no good match
715+
if (i === -1) {
716+
// traverse the directory tree up one level
717+
containingFolder = getParentFolder(containingFolder);
718+
// Are we still inside the project?
719+
if (containingFolder.indexOf(projectRoot) === -1) {
720+
stillInProjectTree = false;
721+
}
722+
} else {
723+
indexFileFound = true;
725724
}
726725
}
727726

727+
if (i !== -1) {
728+
DocumentManager.getDocumentForPath(filteredFiltered[i].fullPath).then(result.resolve, result.resolve);
729+
return;
730+
}
731+
728732
result.resolve(null);
729733
});
730734

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

11681173
if (doc && !doc._masterEditor) {
1174+
otherDocumentsInWorkingFiles = DocumentManager.getWorkingSet().length;
11691175
DocumentManager.addToWorkingSet(doc.file);
1176+
1177+
if (!otherDocumentsInWorkingFiles) {
1178+
DocumentManager.setCurrentDocument(doc);
1179+
}
11701180
}
11711181

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

0 commit comments

Comments
 (0)