From 57204a74a18f3f21882c399cfd4c2f18a41f8217 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Wed, 16 Oct 2013 22:06:47 +0200 Subject: [PATCH 1/3] First try to fix adobe/brackets#5537 --- src/LiveDevelopment/LiveDevelopment.js | 85 ++++++++++++++------------ 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 55bf4f6e0d9..107d0241989 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -569,6 +569,7 @@ define(function LiveDevelopment(require, exports, module) { // to the base URL is completed, and (3) the agents finish loading // gather related documents and finally set status to STATUS_ACTIVE. var doc = _getCurrentDocument(); // TODO: probably wrong... + console.log(doc); if (doc) { var status = STATUS_ACTIVE, @@ -674,57 +675,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); }); From 9308c7412edfdde04a8d81052c33ed4d6c7cdc83 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Thu, 17 Oct 2013 19:29:30 +0200 Subject: [PATCH 2/3] Working fix for adobe/brackets#5537 --- src/LiveDevelopment/LiveDevelopment.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 107d0241989..5705186155d 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -1168,10 +1168,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:) From 73b25b4640e9f64007775734a596697a10aea776 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Thu, 17 Oct 2013 19:42:50 +0200 Subject: [PATCH 3/3] Removed debug code --- src/LiveDevelopment/LiveDevelopment.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 5705186155d..7cdb877b486 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -569,7 +569,6 @@ define(function LiveDevelopment(require, exports, module) { // to the base URL is completed, and (3) the agents finish loading // gather related documents and finally set status to STATUS_ACTIVE. var doc = _getCurrentDocument(); // TODO: probably wrong... - console.log(doc); if (doc) { var status = STATUS_ACTIVE,