Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tvoliter/context-menus
Browse files Browse the repository at this point in the history
* origin/master: (33 commits)
  code review comments
  Update comments
  Update CodeMirror SHA
  code review fixes
  Restore Shift-Tab to outdent behavior
  Re-implement performance suite filtering due to RequireJS changes in SpecRunner
  Revert .json file listing of test suites.
  Add ExtensionUtils to root require context
  added a comment explaining why we aren't using jquery deferreds for the done loading notification
  Fix adobe#971 (Find in Files treats \n, \r, etc. as regular expressions) -- Escape backslash too (and simplify escaping regexp to use char class instead of |).
  createTestWindowAndRun now waits for brackets to be completely done loading (so extensions are loaded before tests run)
  added a 'ready' event to brackets that fires when brackets is completely done loading
  Rewrote unit tests for JavaScriptInlineEditor to get JSUtils from the require context that was used to load the extension. We only need to do this in unit tests where we rely on JSUtils to get the DocumentManager, etc. from the current window.
  Modified ExtensionLoader to allow for retrieving the require context that loaded an extension
  Refactor loadStyleSheet. Change error handling.
  provide way for unit tests to restore commands after a reset
  Fixed bug where triangle wasn't updating correctly by toggling "scroll" events on double click show
  Fix for double-click not working
  Removed unused comments
  Code review fixes.
  ...
  • Loading branch information
tvoliter committed Jun 13, 2012
2 parents 2ec6641 + 71d8783 commit f2fb32b
Show file tree
Hide file tree
Showing 23 changed files with 561 additions and 186 deletions.
56 changes: 53 additions & 3 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,47 @@ define(function (require, exports, module) {
ExtensionLoader = require("utils/ExtensionLoader"),
SidebarView = require("project/SidebarView"),
Async = require("utils/Async");

// Local variables
var bracketsReady = false,
bracketsReadyHandlers = [];

//Load modules that self-register and just need to get included in the main project
require("editor/CodeHintManager");
require("editor/EditorCommandHandlers");
require("debug/DebugCommandHandlers");
require("view/ViewCommandHandlers");
require("search/FindInFiles");
require("utils/ExtensionUtils");

function _callBracketsReadyHandler(handler) {
try {
handler();
} catch (e) {
console.log("Exception when calling a 'brackets done loading' handler");
console.log(e);
}
}

function _onBracketsReady() {
var i;
bracketsReady = true;
for (i = 0; i < bracketsReadyHandlers.length; i++) {
_callBracketsReadyHandler(bracketsReadyHandlers[i]);
}
bracketsReadyHandlers = [];
}

// WARNING: This event won't fire if ANY extension fails to load or throws an error during init.
// To fix this, we need to make a change to _initExtensions (filed as issue 1029)
function _registerBracketsReadyHandler(handler) {
if (bracketsReady) {
_callBracketsReadyHandler(handler);
} else {
bracketsReadyHandlers.push(handler);
}
}

// TODO: Issue 949 - the following code should be shared

function _initGlobalBrackets() {
Expand Down Expand Up @@ -119,10 +152,22 @@ define(function (require, exports, module) {
// Note: we change the name to "getModule" because this won't do exactly the same thing as 'require' in AMD-wrapped
// modules. The extension will only be able to load modules that have already been loaded once.
brackets.getModule = require;

// Provide a way for anyone (including code not using require) to register a handler for the brackets 'ready' event
// This event is like $(document).ready in that it will call the handler immediately if brackets is already done loading
//
// WARNING: This event won't fire if ANY extension fails to load or throws an error during init.
// To fix this, we need to make a change to _initExtensions (filed as issue 1029)
//
// TODO (issue 1034): We *could* use a $.Deferred for this, except deferred objects enter a broken
// state if any resolution callback throws an exception. Since third parties (e.g. extensions) may
// add callbacks to this, we need to be robust to exceptions
brackets.ready = _registerBracketsReadyHandler;
}

// TODO: (issue 1029) Add timeout to main extension loading promise, so that we always call this function
// Making this fix will fix a warning (search for issue 1029) related to the brackets 'ready' event.
function _initExtensions() {
// FUTURE (JRB): As we get more fine-grained performance measurement, move this out of core application startup
return Async.doInParallel(["default", "user"], function (item) {
return ExtensionLoader.loadAllExtensionsInNativeDirectory(
FileUtils.getNativeBracketsDirectoryPath() + "/extensions/" + item,
Expand Down Expand Up @@ -156,8 +201,13 @@ define(function (require, exports, module) {
CSSUtils : require("language/CSSUtils"),
LiveDevelopment : require("LiveDevelopment/LiveDevelopment"),
Inspector : require("LiveDevelopment/Inspector/Inspector"),
NativeApp : require("utils/NativeApp")
NativeApp : require("utils/NativeApp"),
doneLoading : false
};

brackets.ready(function () {
brackets.test.doneLoading = true;
});
}

function _initDragAndDropListeners() {
Expand Down Expand Up @@ -261,7 +311,7 @@ define(function (require, exports, module) {
// finish UI initialization before loading extensions
ProjectManager.loadProject().done(function () {
_initTest();
_initExtensions();
_initExtensions().always(_onBracketsReady);
});
}

Expand Down
36 changes: 28 additions & 8 deletions src/command/CommandManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ define(function (require, exports, module) {
* @type Object.<commandID: string, Command>
*/
var _commands = {};


/**
* Temporary copy of commands map for restoring after testing
* TODO (issue #1039): implement separate require contexts for unit tests
* @type Object.<commandID: string, Command>
*/
var _commandsOriginal = {};

/**
* @constructor
* @private
Expand Down Expand Up @@ -174,11 +181,23 @@ define(function (require, exports, module) {
return command;
}


function _reset() {
/**
* Clear all commands for unit testing, but first make copy of commands so that
* they can be restored afterward
*/
function _testReset() {
_commandsOriginal = _commands;
_commands = {};
}

/**
* Restore original commands after test and release copy
*/
function _testRestore(commands) {
_commands = _commandsOriginal;
_commandsOriginal = {};
}

/**
* Retrieves a Command object by id
* @param {string} id
Expand All @@ -204,8 +223,9 @@ define(function (require, exports, module) {
}

// Define public API
exports.register = register;
exports.execute = execute;
exports.get = get;
exports._reset = _reset;
});
exports.register = register;
exports.execute = execute;
exports.get = get;
exports._testReset = _testReset;
exports._testRestore = _testRestore;
});
11 changes: 6 additions & 5 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,24 +314,25 @@ define(function (require, exports, module) {

// Editor supplies some standard keyboard behavior extensions of its own
var codeMirrorKeyMap = {
"Tab" : _handleTabKey,
"Tab": _handleTabKey,
"Shift-Tab": "indentLess",

"Left" : function (instance) {
"Left": function (instance) {
if (!_handleSoftTabNavigation(instance, -1, "moveH")) {
CodeMirror.commands.goCharLeft(instance);
}
},
"Right" : function (instance) {
"Right": function (instance) {
if (!_handleSoftTabNavigation(instance, 1, "moveH")) {
CodeMirror.commands.goCharRight(instance);
}
},
"Backspace" : function (instance) {
"Backspace": function (instance) {
if (!_handleSoftTabNavigation(instance, -1, "deleteH")) {
CodeMirror.commands.delCharLeft(instance);
}
},
"Delete" : function (instance) {
"Delete": function (instance) {
if (!_handleSoftTabNavigation(instance, 1, "deleteH")) {
CodeMirror.commands.delCharRight(instance);
}
Expand Down
30 changes: 19 additions & 11 deletions src/extensions/disabled/JavaScriptInlineEditor/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define(function (require, exports, module) {

var extensionPath = FileUtils.getNativeModuleDirectoryPath(module);

describe("JSQuickEdit", function () {
describe("JavaScriptInlineEditor", function () {

var testPath = extensionPath + "/unittest-files",
testWindow,
Expand Down Expand Up @@ -495,7 +495,6 @@ define(function (require, exports, module) {
SpecRunnerUtils.closeTestWindow();
});

/***
it("should return the correct offsets if the file has changed", function () {
var didOpen = false,
gotError = false;
Expand Down Expand Up @@ -531,8 +530,11 @@ define(function (require, exports, module) {

FileIndexManager.getFileInfoList("all")
.done(function (fileInfos) {
var extensionRequire = brackets.getModule('utils/ExtensionLoader').getRequireContextForExtension('JavaScriptInlineEditor');
var JSUtilsInExtension = extensionRequire("JSUtils");

// Look for "edit2" function
JSUtils.findMatchingFunctions("edit2", fileInfos)
JSUtilsInExtension.findMatchingFunctions("edit2", fileInfos)
.done(function (result) { functions = result; });
});
});
Expand All @@ -545,8 +547,7 @@ define(function (require, exports, module) {
expect(functions[0].lineEnd).toBe(13);
});
});
***/
/***

it("should return a newly created function in an unsaved file", function () {
var didOpen = false,
gotError = false;
Expand All @@ -563,24 +564,31 @@ define(function (require, exports, module) {

runs(function () {
var doc = DocumentManager.getCurrentDocument();
// Add a new function to the file
doc.setText(doc.getText() + "\n\nfunction TESTFUNCTION() {\n return true;\n}\n");

// Look for the selector we just created
JSUtils.findMatchingFunctions("TESTFUNCTION", FileIndexManager.getFileInfoList("all"))
.done(function (result) { functions = result; });
FileIndexManager.getFileInfoList("all")
.done(function (fileInfos) {
var extensionRequire = brackets.getModule('utils/ExtensionLoader').getRequireContextForExtension('JavaScriptInlineEditor');
var JSUtilsInExtension = extensionRequire("JSUtils");

// Look for "TESTFUNCTION" function
JSUtilsInExtension.findMatchingFunctions("TESTFUNCTION", fileInfos)
.done(function (result) {
functions = result;
});
});
});

waitsFor(function () { return functions !== null; }, "JSUtils.findMatchingFunctions() timeout", 1000);

runs(function () {
expect(functions.length).toBe(1);
expect(functions[0].lineStart).toBe(24);
expect(functions[0].lineEnd).toBe(26);
expect(functions[0].lineStart).toBe(33);
expect(functions[0].lineEnd).toBe(35);
});
});
***/
});
}); //describe("JS Parsing")
});
Expand Down
24 changes: 3 additions & 21 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,34 +851,16 @@ define(function (require, exports, module) {
_projectTree.jstree("create", node, position, {data: initialName}, null, skipRename);

if (!skipRename) {
var $renameInput = _projectTree.find(".jstree-rename-input"),
projectTreeOffset = _projectTree.offset(),
projectTreeScroller = _projectTree.get(0),
renameInput = $renameInput.get(0),
renameInputOffset = $renameInput.offset();
var $renameInput = _projectTree.find(".jstree-rename-input");

$renameInput.on("keydown", function (event) {
// Listen for escape key on keydown, so we can remove the node in the create.jstree handler above
if (event.keyCode === 27) {
escapeKeyPressed = true;
}
});

// make sure edit box is visible within the jstree, only scroll vertically when necessary
if (renameInputOffset.top + $renameInput.height() >= (projectTreeOffset.top + _projectTree.height())) {
// below viewport
renameInput.scrollIntoView(false);
} else if (renameInputOffset.top <= projectTreeOffset.top) {
// above viewport
renameInput.scrollIntoView(true);
}

// left-align renameInput
if (renameInputOffset.left < 0) {
_projectTree.scrollLeft(_projectTree.scrollLeft() + renameInputOffset.left);
} else if (renameInputOffset.left + $renameInput.width() >= projectTreeOffset.left + _projectTree.width()) {
_projectTree.scrollLeft(renameInputOffset.left - projectTreeOffset.left);
}

ViewUtils.scrollElementIntoView(_projectTree, $renameInput, true);
}

return result.promise();
Expand Down
Loading

0 comments on commit f2fb32b

Please sign in to comment.