Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
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
51 changes: 13 additions & 38 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,14 @@
* # STATUS
*
* Status updates are dispatched as `statusChange` jQuery events. The status
* is passed as the first parameter and the reason for the change as the second
* parameter. Currently only the "Inactive" status supports the reason parameter.
* The status codes are:
* codes are:
*
* -1: Error
* 0: Inactive
* 1: Connecting to the remote debugger
* 2: Loading agents
* 3: Active
* 4: Out of sync
*
* The reason codes are:
* - null (Unknown reason)
* - "explicit_close" (LiveDevelopment.close() was called)
* - "navigated_away" (The browser changed to a location outside of the project)
* - "detached_target_closed" (The tab or window was closed)
* - "detached_replaced_with_devtools" (The developer tools were opened in the browser)
*/
define(function LiveDevelopment(require, exports, module) {
"use strict";
Expand All @@ -78,6 +69,7 @@ define(function LiveDevelopment(require, exports, module) {
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
FileUtils = require("file/FileUtils"),
HTMLInstrumentation = require("language/HTMLInstrumentation"),
LiveDevServerManager = require("LiveDevelopment/LiveDevServerManager"),
NativeFileError = require("file/NativeFileError"),
NativeApp = require("utils/NativeApp"),
Expand Down Expand Up @@ -142,8 +134,7 @@ define(function LiveDevelopment(require, exports, module) {
var _liveDocument; // the document open for live editing.
var _relatedDocuments; // CSS and JS documents that are used by the live HTML document
var _serverProvider; // current LiveDevServerProvider
var _closeReason; // reason why live preview was closed


function _isHtmlFileExt(ext) {
return (FileUtils.isStaticHtmlFileExt(ext) ||
(ProjectManager.getBaseUrl() && FileUtils.isServerHtmlFileExt(ext)));
Expand Down Expand Up @@ -461,14 +452,8 @@ define(function LiveDevelopment(require, exports, module) {
* @param {integer} new status
*/
function _setStatus(status) {
// Don't send a notification when the status didn't actually change
if (status === exports.status) {
return;
}

exports.status = status;
var reason = status === STATUS_INACTIVE ? _closeReason : null;
$(exports).triggerHandler("statusChange", [status, reason]);
$(exports).triggerHandler("statusChange", status);
}

/** Triggered by Inspector.error */
Expand Down Expand Up @@ -520,6 +505,13 @@ define(function LiveDevelopment(require, exports, module) {
});
}

/** Triggered by Inspector.detached */
function _onDetached(event, res) {
// res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
// Sample list taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
}

// WebInspector Event: Page.frameNavigated
function _onFrameNavigated(event, res) {
// res = {frame}
Expand Down Expand Up @@ -548,7 +540,6 @@ define(function LiveDevelopment(require, exports, module) {
if (!url.match(baseUrlRegExp)) {
// No longer in site, so terminate live dev, but don't close browser window
Inspector.disconnect();
_closeReason = "navigated_away";
_setStatus(STATUS_INACTIVE);
_serverProvider = null;
}
Expand All @@ -564,22 +555,10 @@ define(function LiveDevelopment(require, exports, module) {
_setStatus(STATUS_INACTIVE);
}

function _onDetached(event, res) {
// If there already is a reason for closing the session, do not overwrite it
if (!_closeReason) {
// Get the explanation from res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
// Examples taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
// Prefix with "detached_" to create a quasi-namespace for Chrome's reasons
_closeReason = "detached_" + res.reason;
}
}

function reconnect() {
unloadAgents();

_setStatus(STATUS_LOADING_AGENTS);
var promises = loadAgents();
_setStatus(STATUS_LOADING_AGENTS);
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
}

Expand All @@ -591,8 +570,6 @@ define(function LiveDevelopment(require, exports, module) {
var browserStarted = false;
var retryCount = 0;

_closeReason = null;

function showWrongDocError() {
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
Expand Down Expand Up @@ -746,8 +723,6 @@ define(function LiveDevelopment(require, exports, module) {
* @return {jQuery.Promise} Resolves once the connection is closed
*/
function close() {
_closeReason = "explicit_close";

var deferred = $.Deferred();

/*
Expand Down Expand Up @@ -861,6 +836,7 @@ define(function LiveDevelopment(require, exports, module) {
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
}

$(Inspector.Inspector).on("detached.livedev", _onDetached);
$(Inspector.Page).on("frameNavigated.livedev", _onFrameNavigated);

waitForInterstitialPageLoad()
Expand Down Expand Up @@ -985,7 +961,6 @@ define(function LiveDevelopment(require, exports, module) {
$(Inspector).on("connect", _onConnect)
.on("disconnect", _onDisconnect)
.on("error", _onError);
$(Inspector.Inspector).on("detached", _onDetached);
$(DocumentManager).on("currentDocumentChange", _onDocumentChange)
.on("documentSaved", _onDocumentSaved)
.on("dirtyFlagChange", _onDirtyFlagChange);
Expand Down
36 changes: 2 additions & 34 deletions src/LiveDevelopment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ define(function main(require, exports, module) {
Dialogs = require("widgets/Dialogs"),
UrlParams = require("utils/UrlParams").UrlParams,
Strings = require("strings"),
ExtensionUtils = require("utils/ExtensionUtils"),
StringUtils = require("utils/StringUtils");
ExtensionUtils = require("utils/ExtensionUtils");

var prefs;
var params = new UrlParams();
Expand Down Expand Up @@ -132,48 +131,17 @@ define(function main(require, exports, module) {
}
}

/** Called on status change */
function _showStatusChangeReason(reason) {
// Destroy the previous twipsy (options are not updated otherwise)
_$btnGoLive.twipsy("hide").removeData("twipsy");

// If there was no reason or the action was an explicit request by the user, don't show a twipsy
if (!reason || reason === "explicit_close") {
return;
}

// Translate the reason
var translatedReason = Strings["LIVE_DEV_" + reason.toUpperCase()];
if (!translatedReason) {
translatedReason = StringUtils.format(Strings.LIVE_DEV_CLOSED_UNKNOWN_REASON, reason);
}

// Configure the twipsy
var options = {
placement: "left",
trigger: "manual",
autoHideDelay: 5000,
title: function () {
return translatedReason;
}
};

// Show the twipsy with the explanation
_$btnGoLive.twipsy(options).twipsy("show");
}

/** Create the menu item "Go Live" */
function _setupGoLiveButton() {
_$btnGoLive = $("#toolbar-go-live");
_$btnGoLive.click(function onGoLive() {
_handleGoLiveCommand();
});
$(LiveDevelopment).on("statusChange", function statusChange(event, status, reason) {
$(LiveDevelopment).on("statusChange", function statusChange(event, status) {
// status starts at -1 (error), so add one when looking up name and style
// See the comments at the top of LiveDevelopment.js for details on the
// various status codes.
_setLabel(_$btnGoLive, null, _statusStyle[status + 1], _statusTooltip[status + 1]);
_showStatusChangeReason(reason);
if (config.autoconnect) {
window.sessionStorage.setItem("live.enabled", status === 3);
}
Expand Down
1 change: 0 additions & 1 deletion src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ define(function (require, exports, module) {
// Load dependent non-module scripts
require("widgets/bootstrap-dropdown");
require("widgets/bootstrap-modal");
require("widgets/bootstrap-twipsy-mod");
require("thirdparty/path-utils/path-utils.min");
require("thirdparty/smart-auto-complete/jquery.smart_autocomplete");

Expand Down
74 changes: 22 additions & 52 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,23 @@ define(function (require, exports, module) {


/**
* Insertion position constants
* Used by addMenu(), addMenuItem(), and addSubMenu() to
* specify the relative position of a newly created menu object
* @enum {string}
*/
var BEFORE = "before",
AFTER = "after",
FIRST = "first",
LAST = "last",
FIRST_IN_SECTION = "firstInSection",
LAST_IN_SECTION = "lastInSection";

/**
* Other constants
*/
* Insertion position constants
* Used by addMenu(), addMenuItem(), and addSubMenu() to
* specify the relative position of a newly created menu object
* @enum {string}
*/
var BEFORE = "before";
var AFTER = "after";
var FIRST = "first";
var LAST = "last";
var FIRST_IN_SECTION = "firstInSection";
var LAST_IN_SECTION = "lastInSection";

/**
* Other constants
*/
var DIVIDER = "---";

/**
* Error Codes from Brackets Shell
* @enum {number}
*/
var NO_ERROR = 0,
ERR_UNKNOWN = 1,
ERR_INVALID_PARAMS = 2,
ERR_NOT_FOUND = 3;


/**
* Maps menuID's to Menu objects
* @type {Object.<string, Menu>}
Expand Down Expand Up @@ -471,8 +462,7 @@ define(function (require, exports, module) {
* @return {MenuItem} the newly created MenuItem
*/
Menu.prototype.addMenuItem = function (command, keyBindings, position, relativeID) {
var menuID = this.id,
id,
var id,
$menuItem,
$link,
menuItem,
Expand Down Expand Up @@ -557,17 +547,8 @@ define(function (require, exports, module) {
}

brackets.app.addMenuItem(this.id, name, commandID, bindingStr, displayStr, position, relativeID, function (err) {
switch (err) {
case NO_ERROR:
break;
case ERR_INVALID_PARAMS:
console.error("addMenuItem(): Invalid Parameters when adding the command " + commandID);
break;
case ERR_NOT_FOUND:
console.error("_getRelativeMenuItem(): MenuItem with Command id " + relativeID + " not found in the Menu " + menuID);
break;
default:
console.error("addMenuItem(); Unknown Error (" + err + ") when adding the command " + commandID);
if (err) {
console.error("addMenuItem() -- error: " + err + " when adding command: " + commandID);
}
});
menuItem.isNative = true;
Expand Down Expand Up @@ -819,26 +800,15 @@ define(function (require, exports, module) {

if (!_isHTMLMenu(id)) {
brackets.app.addMenu(name, id, position, relativeID, function (err) {
switch (err) {
case NO_ERROR:
if (err) {
console.error("addMenu() -- error: " + err + " when adding menu with ID: " + id);
} else {
// Make sure name is up to date
brackets.app.setMenuTitle(id, name, function (err) {
if (err) {
console.error("setMenuTitle() -- error: " + err);
}
});
break;
case ERR_UNKNOWN:
console.error("addMenu(): Unknown Error when adding the menu " + id);
break;
case ERR_INVALID_PARAMS:
console.error("addMenu(): Invalid Parameters when adding the menu " + id);
break;
case ERR_NOT_FOUND:
console.error("addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id);
break;
default:
console.error("addMenu(): Unknown Error (" + err + ") when adding the menu " + id);
}
});
return menu;
Expand Down
8 changes: 0 additions & 8 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,14 +814,6 @@ define(function (require, exports, module) {
* given new text; if text == "", then the entire range is effectively deleted. If 'end' is omitted,
* then the new text is inserted at that point and all existing text is preserved. Line endings will
* be rewritten to match the document's current line-ending style.
*
* IMPORTANT NOTE: Because of #1688, do not use this in cases where you might be
* operating on a linked document (like the main document for an inline editor)
* during an outer CodeMirror operation (like a key event that's handled by the
* editor itself). A common case of this is code hints in inline editors. In
* such cases, use `editor._codeMirror.replaceRange()` instead. This should be
* fixed when we migrate to use CodeMirror's native document-linking functionality.
*
* @param {!string} text Text to insert or replace the range with
* @param {!{line:number, ch:number}} start Start of range, inclusive (if 'to' specified) or insertion point (if not)
* @param {?{line:number, ch:number}} end End of range, exclusive; optional
Expand Down
12 changes: 6 additions & 6 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ define(function (require, exports, module) {
var result, text, line;

// Move the context to the first non-empty token.
if (!ctx.token.className && ctx.token.string.trim().length === 0) {
if (!ctx.token.type && ctx.token.string.trim().length === 0) {
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx);
}

Expand All @@ -300,7 +300,7 @@ define(function (require, exports, module) {
}

// If we aren't in a block-comment.
if (!result || ctx.token.className !== "comment" || ctx.token.string.match(suffixExp)) {
if (!result || ctx.token.type !== "comment" || ctx.token.string.match(suffixExp)) {
// Is a range of text selected? (vs just an insertion pt)
var hasSelection = (sel.start.line !== sel.end.line) || (sel.start.ch !== sel.end.ch);

Expand All @@ -325,12 +325,12 @@ define(function (require, exports, module) {

// If we are in a selection starting and ending in invalid tokens and with no content (not considering spaces),
// find if we are inside a block-comment.
} else if (startCtx.token.className === null && endCtx.token.className === null &&
} else if (startCtx.token.type === null && endCtx.token.type === null &&
!editor.posWithinRange(ctx.pos, startCtx.pos, endCtx.pos, true)) {
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, startCtx);

// We found a comment, find the start and end and check if the selection is inside the block-comment.
if (startCtx.token.className === "comment") {
if (startCtx.token.type === "comment") {
prefixPos = _findCommentStart(startCtx, prefixExp);
suffixPos = _findCommentEnd(startCtx, suffixExp, suffix.length);

Expand All @@ -342,7 +342,7 @@ define(function (require, exports, module) {
}

// If the start is inside a comment, find the prefix and suffix positions.
} else if (ctx.token.className === "comment") {
} else if (ctx.token.type === "comment") {
prefixPos = _findCommentStart(ctx, prefixExp);
suffixPos = _findCommentEnd(ctx, suffixExp, suffix.length);

Expand Down Expand Up @@ -489,7 +489,7 @@ define(function (require, exports, module) {
// If the selection includes a comment or is already a line selection, delegate to Block-Comment
var ctx = TokenUtils.getInitialContext(editor._codeMirror, {line: selStart.line, ch: selStart.ch});
var result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx);
var className = ctx.token.className;
var className = ctx.token.type;
result = result && _findNextBlockComment(ctx, selEnd, prefixExp);

if (className === "comment" || result || isLineSelection) {
Expand Down
8 changes: 0 additions & 8 deletions src/extensions/default/HTMLCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@ define(function (require, exports, module) {
hintList = expectHints(HTMLCodeHints.tagHintProvider);
verifyTagHints(hintList);
});

//Test for issue #3339
it("should show HTML hints after HTML Entity on same line", function () {
testDocument.replaceRange("&nbsp; Test < ", { line: 8, ch: 0 });
testEditor.setCursorPos({ line: 8, ch: 13 }); // cursor between < and some trailing whitespaces
var hintList = expectHints(HTMLCodeHints.tagHintProvider);
verifyTagHints(hintList);
});
});

describe("Attribute name hint provider", function () {
Expand Down
Loading