diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 491257387a0..d1aed613754 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -81,6 +81,9 @@ define(function (require, exports, module) { /** @type {Number} index to use for next, new Untitled document */ var _nextUntitledIndexToUse = 1; + /** @type {boolean} prevents reentrancy of browserReload() */ + var _isReloading = false; + /** Unique token used to indicate user-driven cancellation of Save As (as opposed to file IO error) */ var USER_CANCELED = { userCanceled: true }; @@ -1438,12 +1441,18 @@ define(function (require, exports, module) { return result.promise(); } - + /** * Does a full reload of the browser window * @param {string} href The url to reload into the window */ function browserReload(href) { + if (_isReloading) { + return; + } + + _isReloading = true; + return CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true }).done(function () { // Give everyone a chance to save their state - but don't let any problems block // us from quitting @@ -1452,7 +1461,7 @@ define(function (require, exports, module) { } catch (ex) { console.error(ex); } - + // Disable the cache to make reloads work _disableCache().always(function () { // Remove all menus to assure every part of Brackets is reloaded @@ -1462,6 +1471,8 @@ define(function (require, exports, module) { window.location.href = href; }); + }).fail(function () { + _isReloading = false; }); }