Skip to content

Commit 667094c

Browse files
committed
fixed some of the issues mentioned in the review
1 parent 93c5a38 commit 667094c

File tree

8 files changed

+65
-22
lines changed

8 files changed

+65
-22
lines changed

src/LiveDevelopment/LiveDevelopment.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ define(function LiveDevelopment(require, exports, module) {
655655
return path.substring(0, path.lastIndexOf('/', path.length - 2) + 1);
656656
}
657657

658+
function getFilenameWithoutExtension(filename) {
659+
var index = filename.lastIndexOf(".");
660+
return index === -1 ? filename : filename.slice(0, index);
661+
}
662+
658663
// Is the currently opened document already a file we can use for Live Development?
659664
if (doc) {
660665
refPath = doc.file.fullPath;
@@ -668,34 +673,38 @@ define(function LiveDevelopment(require, exports, module) {
668673
var baseUrl = ProjectManager.getBaseUrl(),
669674
hasOwnServerForLiveDevelopment = (baseUrl && baseUrl.length);
670675

671-
// TODO: It would be better to reuse the list of file extensions from FileUtils
672-
var staticIndexFiles = ["html", "htm"].map(function (extension) { return "index." + extension; });
673-
var dynamicIndexFiles = ["php", "php3", "php4", "php5", "phtm", "phtml", "cfm", "cfml", "asp", "aspx", "jsp", "jspx", "shtm", "shtml"].map(function (extension) { return "index." + extension; });
674-
675676
FileIndexManager.getFileInfoList("all").done(function (allFiles) {
676677
if (refPath) {
677678
var projectRoot = ProjectManager.getProjectRoot().fullPath,
678679
containingFolder = FileUtils.getDirectoryPath(refPath),
679680
indexFileFound = false,
680681
stillInProjectTree = true;
681682

683+
var filteredFiltered = allFiles.filter(function (item) {
684+
var parent = getParentFolder(item.fullPath);
685+
686+
return (containingFolder.indexOf(parent) === 0);
687+
});
688+
682689
var filterIndexFile = function (fileInfo) {
683690
if (fileInfo.fullPath.indexOf(containingFolder) === 0) {
684-
if (hasOwnServerForLiveDevelopment) {
685-
if ((dynamicIndexFiles.indexOf(fileInfo.name) !== -1) ||
686-
(staticIndexFiles.indexOf(fileInfo.name) !== -1)) {
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)) {
687698
return true;
688699
}
689-
} else if (staticIndexFiles.indexOf(fileInfo.name) !== -1) {
690-
return true;
700+
} else {
701+
return false;
691702
}
692-
} else {
693-
return false;
694703
}
695704
};
696705

697706
while (!indexFileFound && stillInProjectTree) {
698-
i = CollectionUtils.indexOf(allFiles, filterIndexFile);
707+
i = CollectionUtils.indexOf(filteredFiltered, filterIndexFile);
699708

700709
// We found no good match
701710
if (i === -1) {
@@ -711,7 +720,7 @@ define(function LiveDevelopment(require, exports, module) {
711720
}
712721

713722
if (i !== -1) {
714-
DocumentManager.getDocumentForPath(allFiles[i].fullPath).then(result.resolve, result.resolve);
723+
DocumentManager.getDocumentForPath(filteredFiltered[i].fullPath).then(result.resolve, result.resolve);
715724
return;
716725
}
717726
}

src/file/FileUtils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,28 +365,28 @@ define(function (require, exports, module) {
365365

366366
/**
367367
* Determine if file extension is a static html file extension.
368-
* @param {string} fileExt file name with extension or just a file extension
368+
* @param {string} filePath could be a path, a file name or just a file extension
369369
* @return {boolean} Returns true if fileExt is in the list
370370
*/
371-
function isStaticHtmlFileExt(fileExt) {
372-
if (!fileExt) {
371+
function isStaticHtmlFileExt(filePath) {
372+
if (!filePath) {
373373
return false;
374374
}
375375

376-
return (_staticHtmlFileExts.indexOf(getFileExtension(fileExt).toLowerCase()) !== -1);
376+
return (_staticHtmlFileExts.indexOf(getFileExtension(filePath).toLowerCase()) !== -1);
377377
}
378378

379379
/**
380380
* Determine if file extension is a server html file extension.
381-
* @param {string} fileExt file name with extension or just a file extension
381+
* @param {string} filePath could be a path, a file name or just a file extension
382382
* @return {boolean} Returns true if fileExt is in the list
383383
*/
384-
function isServerHtmlFileExt(fileExt) {
385-
if (!fileExt) {
384+
function isServerHtmlFileExt(filePath) {
385+
if (!filePath) {
386386
return false;
387387
}
388388

389-
return (_serverHtmlFileExts.indexOf(getFileExtension(fileExt).toLowerCase()) !== -1);
389+
return (_serverHtmlFileExts.indexOf(getFileExtension(filePath).toLowerCase()) !== -1);
390390
}
391391

392392
/**
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<html>
2+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background-color: red }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
<html>
2+
<head>
3+
<link rel="stylesheet" href="test.css" />
4+
</head>
5+
6+
<body>
7+
</body>
28
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<html>
2+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background-color: red }

test/spec/LiveDevelopment-test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,6 @@ define(function (require, exports, module) {
10701070

10711071
loadFileAndUpdateFileIndex(cssFile);
10721072

1073-
brackets.app.showDeveloperTools();
10741073
runs(function () {
10751074
promise = LiveDevelopment._getInitialDocFromCurrent();
10761075

@@ -1157,6 +1156,29 @@ define(function (require, exports, module) {
11571156
expect(document.file.fullPath).toBe(testPath + "/static-project-5/" + indexFile);
11581157
});
11591158
});
1159+
1160+
it("should not find any HTML page", function () {
1161+
var promise,
1162+
document;
1163+
var cssFile = "top2/test.css";
1164+
1165+
SpecRunnerUtils.loadProjectInTestWindow(testPath + "/static-project-6");
1166+
loadFileAndUpdateFileIndex(cssFile);
1167+
1168+
runs(function () {
1169+
promise = LiveDevelopment._getInitialDocFromCurrent();
1170+
1171+
promise.done(function (doc) {
1172+
document = doc;
1173+
});
1174+
1175+
waitsForDone(promise);
1176+
});
1177+
1178+
runs(function () {
1179+
expect(document).toBe(null);
1180+
});
1181+
});
11601182
});
11611183

11621184
describe("Find dynamic page for Live Development", function () {

0 commit comments

Comments
 (0)