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

Bug: 12766 - Now language mode can be changed for unsaved Untitled Do… #13086

Merged
merged 1 commit into from
Feb 16, 2017
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
11 changes: 5 additions & 6 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
@@ -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;

2 changes: 0 additions & 2 deletions src/editor/EditorStatusBar.js
Original file line number Diff line number Diff line change
@@ -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());
}
95 changes: 51 additions & 44 deletions src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
@@ -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]);
}
});
}

6 changes: 4 additions & 2 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
}

14 changes: 9 additions & 5 deletions src/view/MainViewManager.js
Original file line number Diff line number Diff line change
@@ -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);