From 0ba601ffa97b94b8b0d0d18ecc6902132efc9363 Mon Sep 17 00:00:00 2001 From: Saurabh Kathpalia Date: Wed, 8 Feb 2017 15:03:07 +0530 Subject: [PATCH] Bug: 12766 - Now language mode can be changed for unsaved Untitled Documents --- src/document/DocumentManager.js | 11 +-- src/editor/EditorStatusBar.js | 2 - .../JavaScriptCodeHints/ScopeManager.js | 95 ++++++++++--------- src/search/FindInFiles.js | 6 +- src/view/MainViewManager.js | 14 ++- 5 files changed, 69 insertions(+), 59 deletions(-) diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index e2a477ded09..b6b1bead62d 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -332,11 +332,13 @@ define(function (require, exports, module) { // use existing document return new $.Deferred().resolve(doc).promise(); } else { + var result = new $.Deferred(), + promise = result.promise(); - // Should never get here if the fullPath refers to an Untitled document + // return null in case of untitled documents if (fullPath.indexOf(_untitledDocumentPath) === 0) { - console.error("getDocumentForPath called for non-open untitled document: " + fullPath); - return new $.Deferred().reject().promise(); + result.resolve(null); + return promise; } var file = FileSystem.getFileForPath(fullPath), @@ -346,9 +348,6 @@ define(function (require, exports, module) { // wait for the result of a previous request return pendingPromise; } else { - var result = new $.Deferred(), - promise = result.promise(); - // log this document's Promise as pending getDocumentForPath._pendingDocumentPromises[file.id] = promise; diff --git a/src/editor/EditorStatusBar.js b/src/editor/EditorStatusBar.js index 9cec5fddaef..593a91e05c9 100644 --- a/src/editor/EditorStatusBar.js +++ b/src/editor/EditorStatusBar.js @@ -76,8 +76,6 @@ define(function (require, exports, module) { // Ensure width isn't left locked by a previous click of the dropdown (which may not have resulted in a "change" event at the time) languageSelect.$button.css("width", "auto"); - // Setting Untitled documents to non-text mode isn't supported yet, so disable the switcher in that case for now - languageSelect.$button.prop("disabled", doc.isUntitled()); // Show the current language as button title languageSelect.$button.text(lang.getName()); } diff --git a/src/extensions/default/JavaScriptCodeHints/ScopeManager.js b/src/extensions/default/JavaScriptCodeHints/ScopeManager.js index 008ca169566..b7985bb26ca 100644 --- a/src/extensions/default/JavaScriptCodeHints/ScopeManager.js +++ b/src/extensions/default/JavaScriptCodeHints/ScopeManager.js @@ -47,7 +47,8 @@ define(function (require, exports, module) { PreferencesManager = brackets.getModule("preferences/PreferencesManager"), ProjectManager = brackets.getModule("project/ProjectManager"), Strings = brackets.getModule("strings"), - StringUtils = brackets.getModule("utils/StringUtils"); + StringUtils = brackets.getModule("utils/StringUtils"), + InMemoryFile = brackets.getModule("document/InMemoryFile"); var HintUtils = require("HintUtils"), MessageIds = require("MessageIds"), @@ -1168,59 +1169,65 @@ define(function (require, exports, module) { ensurePreferences(); deferredPreferences.done(function () { - FileSystem.resolve(dir, function (err, directory) { - if (err) { - console.error("Error resolving", dir); - addFilesDeferred.resolveWith(null); - return; - } - - directory.getContents(function (err, contents) { + if (!file instanceof InMemoryFile) { + FileSystem.resolve(dir, function (err, directory) { if (err) { - console.error("Error getting contents for", directory); + console.error("Error resolving", dir); addFilesDeferred.resolveWith(null); return; } - var files = contents - .filter(function (entry) { - return entry.isFile && !isFileExcluded(entry); - }) - .map(function (entry) { - return entry.fullPath; - }); + directory.getContents(function (err, contents) { + if (err) { + console.error("Error getting contents for", directory); + addFilesDeferred.resolveWith(null); + return; + } - initTernServer(dir, files); - - var hintsPromise = primePump(path); - hintsPromise.done(function () { - if (!usingModules()) { - // Read the subdirectories of the new file's directory. - // Read them first in case there are too many files to - // read in the project. - addAllFilesAndSubdirectories(dir, function () { - // If the file is in the project root, then read - // all the files under the project root. - var currentDir = (dir + "/"); - if (projectRoot && currentDir !== projectRoot && - currentDir.indexOf(projectRoot) === 0) { - addAllFilesAndSubdirectories(projectRoot, function () { - // prime the pump again but this time don't wait - // for completion. - primePump(path); + var files = contents + .filter(function (entry) { + return entry.isFile && !isFileExcluded(entry); + }) + .map(function (entry) { + return entry.fullPath; + }); + initTernServer(dir, files); + + var hintsPromise = primePump(path); + hintsPromise.done(function () { + if (!usingModules()) { + // Read the subdirectories of the new file's directory. + // Read them first in case there are too many files to + // read in the project. + addAllFilesAndSubdirectories(dir, function () { + // If the file is in the project root, then read + // all the files under the project root. + var currentDir = (dir + "/"); + if (projectRoot && currentDir !== projectRoot && + currentDir.indexOf(projectRoot) === 0) { + addAllFilesAndSubdirectories(projectRoot, function () { + // prime the pump again but this time don't wait + // for completion. + primePump(path); + + addFilesDeferred.resolveWith(null, [_ternWorker]); + }); + } else { addFilesDeferred.resolveWith(null, [_ternWorker]); - }); - } else { - addFilesDeferred.resolveWith(null, [_ternWorker]); - } - }); - } else { - addFilesDeferred.resolveWith(null, [_ternWorker]); - } + } + }); + } else { + addFilesDeferred.resolveWith(null, [_ternWorker]); + } + }); }); }); - }); + } else { + initTernServer(pr, []); + primePump(path); + addFilesDeferred.resolveWith(null, [_ternWorker]); + } }); } diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index 02954dd3bae..26c20f07985 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -452,11 +452,13 @@ define(function (require, exports, module) { */ function _updateDocumentInNode(docPath) { DocumentManager.getDocumentForPath(docPath).done(function (doc) { - var updateObject = { + if (doc) { + var updateObject = { "filePath": docPath, "docContents": doc.getText() }; - searchDomain.exec("documentChanged", updateObject); + searchDomain.exec("documentChanged", updateObject); + } }); } diff --git a/src/view/MainViewManager.js b/src/view/MainViewManager.js index 1ae39be9940..671b370795f 100644 --- a/src/view/MainViewManager.js +++ b/src/view/MainViewManager.js @@ -1273,11 +1273,15 @@ define(function (require, exports, module) { } else { DocumentManager.getDocumentForPath(file.fullPath) .done(function (doc) { - _edit(paneId, doc, $.extend({}, options, { - noPaneActivate: true - })); - doPostOpenActivation(); - result.resolve(doc.file); + if (doc) { + _edit(paneId, doc, $.extend({}, options, { + noPaneActivate: true + })); + doPostOpenActivation(); + result.resolve(doc.file); + } else { + result.resolve(null); + } }) .fail(function (fileError) { result.reject(fileError);