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

Commit 7883b01

Browse files
saurabh95swmitra
authored andcommitted
Bug: 12766 - Now language mode can be changed for unsaved Untitled Documents (#13086)
1 parent 74c5306 commit 7883b01

File tree

5 files changed

+69
-59
lines changed

5 files changed

+69
-59
lines changed

src/document/DocumentManager.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,13 @@ define(function (require, exports, module) {
332332
// use existing document
333333
return new $.Deferred().resolve(doc).promise();
334334
} else {
335+
var result = new $.Deferred(),
336+
promise = result.promise();
335337

336-
// Should never get here if the fullPath refers to an Untitled document
338+
// return null in case of untitled documents
337339
if (fullPath.indexOf(_untitledDocumentPath) === 0) {
338-
console.error("getDocumentForPath called for non-open untitled document: " + fullPath);
339-
return new $.Deferred().reject().promise();
340+
result.resolve(null);
341+
return promise;
340342
}
341343

342344
var file = FileSystem.getFileForPath(fullPath),
@@ -346,9 +348,6 @@ define(function (require, exports, module) {
346348
// wait for the result of a previous request
347349
return pendingPromise;
348350
} else {
349-
var result = new $.Deferred(),
350-
promise = result.promise();
351-
352351
// log this document's Promise as pending
353352
getDocumentForPath._pendingDocumentPromises[file.id] = promise;
354353

src/editor/EditorStatusBar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ define(function (require, exports, module) {
7676

7777
// 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)
7878
languageSelect.$button.css("width", "auto");
79-
// Setting Untitled documents to non-text mode isn't supported yet, so disable the switcher in that case for now
80-
languageSelect.$button.prop("disabled", doc.isUntitled());
8179
// Show the current language as button title
8280
languageSelect.$button.text(lang.getName());
8381
}

src/extensions/default/JavaScriptCodeHints/ScopeManager.js

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ define(function (require, exports, module) {
4747
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
4848
ProjectManager = brackets.getModule("project/ProjectManager"),
4949
Strings = brackets.getModule("strings"),
50-
StringUtils = brackets.getModule("utils/StringUtils");
50+
StringUtils = brackets.getModule("utils/StringUtils"),
51+
InMemoryFile = brackets.getModule("document/InMemoryFile");
5152

5253
var HintUtils = require("HintUtils"),
5354
MessageIds = require("MessageIds"),
@@ -1168,59 +1169,65 @@ define(function (require, exports, module) {
11681169

11691170
ensurePreferences();
11701171
deferredPreferences.done(function () {
1171-
FileSystem.resolve(dir, function (err, directory) {
1172-
if (err) {
1173-
console.error("Error resolving", dir);
1174-
addFilesDeferred.resolveWith(null);
1175-
return;
1176-
}
1177-
1178-
directory.getContents(function (err, contents) {
1172+
if (!file instanceof InMemoryFile) {
1173+
FileSystem.resolve(dir, function (err, directory) {
11791174
if (err) {
1180-
console.error("Error getting contents for", directory);
1175+
console.error("Error resolving", dir);
11811176
addFilesDeferred.resolveWith(null);
11821177
return;
11831178
}
11841179

1185-
var files = contents
1186-
.filter(function (entry) {
1187-
return entry.isFile && !isFileExcluded(entry);
1188-
})
1189-
.map(function (entry) {
1190-
return entry.fullPath;
1191-
});
1180+
directory.getContents(function (err, contents) {
1181+
if (err) {
1182+
console.error("Error getting contents for", directory);
1183+
addFilesDeferred.resolveWith(null);
1184+
return;
1185+
}
11921186

1193-
initTernServer(dir, files);
1194-
1195-
var hintsPromise = primePump(path);
1196-
hintsPromise.done(function () {
1197-
if (!usingModules()) {
1198-
// Read the subdirectories of the new file's directory.
1199-
// Read them first in case there are too many files to
1200-
// read in the project.
1201-
addAllFilesAndSubdirectories(dir, function () {
1202-
// If the file is in the project root, then read
1203-
// all the files under the project root.
1204-
var currentDir = (dir + "/");
1205-
if (projectRoot && currentDir !== projectRoot &&
1206-
currentDir.indexOf(projectRoot) === 0) {
1207-
addAllFilesAndSubdirectories(projectRoot, function () {
1208-
// prime the pump again but this time don't wait
1209-
// for completion.
1210-
primePump(path);
1187+
var files = contents
1188+
.filter(function (entry) {
1189+
return entry.isFile && !isFileExcluded(entry);
1190+
})
1191+
.map(function (entry) {
1192+
return entry.fullPath;
1193+
});
12111194

1195+
initTernServer(dir, files);
1196+
1197+
var hintsPromise = primePump(path);
1198+
hintsPromise.done(function () {
1199+
if (!usingModules()) {
1200+
// Read the subdirectories of the new file's directory.
1201+
// Read them first in case there are too many files to
1202+
// read in the project.
1203+
addAllFilesAndSubdirectories(dir, function () {
1204+
// If the file is in the project root, then read
1205+
// all the files under the project root.
1206+
var currentDir = (dir + "/");
1207+
if (projectRoot && currentDir !== projectRoot &&
1208+
currentDir.indexOf(projectRoot) === 0) {
1209+
addAllFilesAndSubdirectories(projectRoot, function () {
1210+
// prime the pump again but this time don't wait
1211+
// for completion.
1212+
primePump(path);
1213+
1214+
addFilesDeferred.resolveWith(null, [_ternWorker]);
1215+
});
1216+
} else {
12121217
addFilesDeferred.resolveWith(null, [_ternWorker]);
1213-
});
1214-
} else {
1215-
addFilesDeferred.resolveWith(null, [_ternWorker]);
1216-
}
1217-
});
1218-
} else {
1219-
addFilesDeferred.resolveWith(null, [_ternWorker]);
1220-
}
1218+
}
1219+
});
1220+
} else {
1221+
addFilesDeferred.resolveWith(null, [_ternWorker]);
1222+
}
1223+
});
12211224
});
12221225
});
1223-
});
1226+
} else {
1227+
initTernServer(pr, []);
1228+
primePump(path);
1229+
addFilesDeferred.resolveWith(null, [_ternWorker]);
1230+
}
12241231
});
12251232
}
12261233

src/search/FindInFiles.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,13 @@ define(function (require, exports, module) {
452452
*/
453453
function _updateDocumentInNode(docPath) {
454454
DocumentManager.getDocumentForPath(docPath).done(function (doc) {
455-
var updateObject = {
455+
if (doc) {
456+
var updateObject = {
456457
"filePath": docPath,
457458
"docContents": doc.getText()
458459
};
459-
searchDomain.exec("documentChanged", updateObject);
460+
searchDomain.exec("documentChanged", updateObject);
461+
}
460462
});
461463
}
462464

src/view/MainViewManager.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,11 +1273,15 @@ define(function (require, exports, module) {
12731273
} else {
12741274
DocumentManager.getDocumentForPath(file.fullPath)
12751275
.done(function (doc) {
1276-
_edit(paneId, doc, $.extend({}, options, {
1277-
noPaneActivate: true
1278-
}));
1279-
doPostOpenActivation();
1280-
result.resolve(doc.file);
1276+
if (doc) {
1277+
_edit(paneId, doc, $.extend({}, options, {
1278+
noPaneActivate: true
1279+
}));
1280+
doPostOpenActivation();
1281+
result.resolve(doc.file);
1282+
} else {
1283+
result.resolve(null);
1284+
}
12811285
})
12821286
.fail(function (fileError) {
12831287
result.reject(fileError);

0 commit comments

Comments
 (0)