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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tvoliter/issue-1278
Browse files Browse the repository at this point in the history
* origin/master: (23 commits)
  - code review fixes - removed _removePopup() function since complexity of having this helper function isn't worth the savings of reusing the "index" var. I don't except their to be many visible popups at one time, so computing the index more than once isn't costly
  fixes issues #1270 #1271 #1272
  Fix scope of beforeEach/afterEach
  Don't limit ourself in handling key events for html selection only. As we transit to js or css, we still need to dismiss the html code hints popup.
  Code review fixes. Revert menu focus change.
  use public document instead of private _codeMirror
  Fix issue #1240 (Inline editor background doesn't extend all the way to right when scrolling) - CodeMirror changed the way it props its width open such that lineSpace's width is no longer explicitly set to the max width of all the lines (lines wider than the viewport simply overflow it). We were checking this width to decide how wide inline editors must be. However, lineSpace's _content_ is still as wide as the max line (due to the pos of the new widthForcer div) so we can use lineSpace's scrollWidth and still get an accurate number.
  Move the long comment before the corresponding code.
  Code review fixes
  fix return key code
  code review fixes
  initial checkin
  Extract code hint query from tagInfo.tagName instead of extracting it directly from code mirror text using cursor position. Also fix an offset issue in HTMLUtils when the cursor is after white spaces and before a left angle bracket.
  Alternative fix for issue #1028. Add new file in working set, but keep it selected in the project tree since that is where the user created and named the file.
  remove debug code
  fix async loading of extensions. init jasmine after extension tests are loaded
  fix module loading for SpecRunnerUtils
  Additional comments in Menus.js for sections
  Adding function comment blocks to Menus.js
  remove empty menu section test
  ...

Conflicts:
	src/widgets/PopUpManager.js
  • Loading branch information
tvoliter committed Jul 18, 2012
2 parents 3cb092e + 650476d commit 4d87891
Show file tree
Hide file tree
Showing 30 changed files with 449 additions and 201 deletions.
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[submodule "src/thirdparty/CodeMirror2"]
path = src/thirdparty/CodeMirror2
url = git@github.com:adobe/CodeMirror2.git
url = https://github.com/adobe/CodeMirror2.git
[submodule "src/thirdparty/path-utils"]
path = src/thirdparty/path-utils
url = git@github.com:jblas/path-utils.git
url = https://github.com/jblas/path-utils.git
[submodule "src/thirdparty/jslint"]
path = src/thirdparty/jslint
url = git@github.com:douglascrockford/JSLint.git
url = https://github.com/douglascrockford/JSLint.git
[submodule "src/thirdparty/smart-auto-complete"]
path = src/thirdparty/smart-auto-complete
url = git@github.com:laktek/jQuery-Smart-Auto-Complete.git
url = https://github.com/laktek/jQuery-Smart-Auto-Complete.git
2 changes: 1 addition & 1 deletion src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ define(function (require, exports, module) {

//Load modules that self-register and just need to get included in the main project
require("document/ChangedDocumentTracker");
require("editor/CodeHintManager");
require("editor/EditorCommandHandlers");
require("debug/DebugCommandHandlers");
require("view/ViewCommandHandlers");
Expand Down Expand Up @@ -207,6 +206,7 @@ define(function (require, exports, module) {
FileIndexManager : FileIndexManager,
Menus : Menus,
KeyBindingManager : KeyBindingManager,
CodeHintManager : CodeHintManager,
CSSUtils : require("language/CSSUtils"),
LiveDevelopment : require("LiveDevelopment/LiveDevelopment"),
Inspector : require("LiveDevelopment/Inspector/Inspector"),
Expand Down
146 changes: 103 additions & 43 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,41 @@ define(function (require, exports, module) {
* looser coupling to Bracket's internal MenuItems and makes menu organization
* more semantic.
* Use these constants as the "relativeID" parameter when calling addMenuItem() and
* specify a position of FIRST or LAST.
* specify a position of FIRST_IN_SECTION or LAST_IN_SECTION.
*
* Menu sections are denoted by dividers or the beginning/end of a menu
*/
var MenuSection = {
FILE_OPEN_CLOSE_MENU: "file-open-close-menu-section",
FILE_SAVE_MENU: "file-save-menu-section",
FILE_LIVE_MENU: "file-live-menu-section",
// Menu Section Command ID to mark the section
FILE_OPEN_CLOSE_COMMANDS: {sectionMarker: Commands.FILE_NEW},
FILE_SAVE_COMMANDS: {sectionMarker: Commands.FILE_SAVE},
FILE_LIVE: {sectionMarker: Commands.FILE_LIVE_FILE_PREVIEW},

EDIT_SELECTION_COMMANDS: {sectionMarker: Commands.EDIT_SELECT_ALL},
EDIT_FIND: {sectionMarker: Commands.EDIT_FIND},
EDIT_REPLACE_COMMANDS: {sectionMarker: Commands.EDIT_REPLACE},
EDIT_MODIFY_SELECTION: {sectionMarker: Commands.EDIT_INDENT},

EDIT_MODIFY_SELECTION_MENU: "edit-modify-selection-menu-section",
EDIT_FIND_MENU: "find-menu-section",
EDIT_REPLACE_MENU: "replace-menu-section",
EDIT_SELECTED_TEXT_COMMANDS: "selected-text-commands-menu-group",
VIEW_HIDESHOW_COMMANDS: {sectionMarker: Commands.VIEW_HIDE_SIDEBAR},
VIEW_FONTSIZE_COMMANDS: {sectionMarker: Commands.VIEW_INCREASE_FONT_SIZE},

NAVIGATE_GOTO_MENU: "goto-menu-section",
NAVIGATE_QUICK_EDIT_MENU: "quick-edit-menu-section"
NAVIGATE_GOTO_COMMANDS: {sectionMarker: Commands.NAVIGATE_QUICK_OPEN},
NAVIGATE_QUICK_EDIT_COMMANDS: {sectionMarker: Commands.TOGGLE_QUICK_EDIT}
};


/**
* 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 BEFORE = "before";
var AFTER = "after";
var FIRST = "first";
var LAST = "last";
var FIRST_IN_SECTION = "firstInSection";
var LAST_IN_SECTION = "lastInSection";

/**
* Other constants
Expand Down Expand Up @@ -197,6 +206,15 @@ define(function (require, exports, module) {
// Determine where to insert. Default is LAST.
var inserted = false;
if (position) {

// Adjust relative position for menu section positions since $relativeElement
// has already been resolved by _getRelativeMenuItem() to a menuItem
if (position === FIRST_IN_SECTION) {
position = BEFORE;
} else if (position === LAST_IN_SECTION) {
position = AFTER;
}

if (position === FIRST) {
$list.prepend($element);
inserted = true;
Expand Down Expand Up @@ -276,38 +294,68 @@ define(function (require, exports, module) {
this.id = id;
}

Menu.prototype._getMenuItemForCommand = function (command) {
var foundMenuItem, key, menuItem;
for (key in menuItemMap) {
if (menuItemMap.hasOwnProperty(key)) {
menuItem = menuItemMap[key];
if (menuItem.getCommand() === command) {
foundMenuItem = menuItem;
break;
}
}
}
return $(_getHTMLMenuItem(foundMenuItem.id)).closest("li");
};

/**
* Determine relative MenuItem
*
* @param {?string} relativeID - id of command (future: also sub-menu, or menu section).
* @param {?string} relativeID - id of command (future: sub-menu).
* @param {?string} position - only needed when relativeID is a MenuSection
*/
Menu.prototype._getRelativeMenuItem = function (relativeID) {
Menu.prototype._getRelativeMenuItem = function (relativeID, position) {
var $relativeElement,
key,
menuItem,
map,
foundMenuItem;

if (relativeID) {
// Lookup Command for this Command id
var command = CommandManager.get(relativeID);

if (command) {
// Find MenuItem that has this command
for (key in menuItemMap) {
if (menuItemMap.hasOwnProperty(key)) {
menuItem = menuItemMap[key];
if (menuItem.getCommand() === command) {
foundMenuItem = menuItem;
break;
}
if (position === FIRST_IN_SECTION || position === LAST_IN_SECTION) {
if (!relativeID.hasOwnProperty("sectionMarker")) {
console.log("Bad Parameter in _getRelativeMenuItem(): relativeID must be a MenuSection when position refers to a menu section");
}

// Determine the $relativeElement by traversing the sibling list and
// stop at the first divider found
var $sectionMarker = this._getMenuItemForCommand(CommandManager.get(relativeID.sectionMarker));
var $sectionItems = $sectionMarker.siblings();
var $listElem = $sectionMarker;
$relativeElement = $listElem;
while (true) {
$listElem = (position === FIRST_IN_SECTION ? $listElem.prev() : $listElem.next());
if ($listElem.length === 0) {
break;
} else if ($listElem.find(".divider").length > 0) {
break;
} else {
$relativeElement = $listElem;
}
}

if (foundMenuItem) {
$relativeElement = $(_getHTMLMenuItem(foundMenuItem.id)).closest("li");
} else {
// handle FIRST, LAST, BEFORE, & AFTER
var command = CommandManager.get(relativeID);
if (command) {
// Lookup Command for this Command id
// Find MenuItem that has this command
$relativeElement = this._getMenuItemForCommand(command);
}
}

return $relativeElement;
} else {
console.log("Bad Parameter in _getRelativeMenuItem(): relativeID not specified");
}

return $relativeElement;
Expand All @@ -332,9 +380,9 @@ define(function (require, exports, module) {
* one or more key bindings to associate with the supplied command.
* @param {?string} position - constant defining the position of new the MenuItem relative
* to other MenuItems. Default is LAST. (see Insertion position constants).
* @param {?string} relativeID - id of command (future: also sub-menu, or menu section) that
* the new menuItem will be positioned relative to. Required when position is
* AFTER or BEFORE, ignored when position is FIRST or LAST
* @param {?string} relativeID - id of command or menu section (future: sub-menu) that
* the new menuItem will be positioned relative to. Required for all position constants
* except FIRST and LAST.
*
* @return {MenuItem} the newly created MenuItem
*/
Expand Down Expand Up @@ -386,16 +434,12 @@ define(function (require, exports, module) {
$menuItem = $("<li><a href='#' id='" + id + "'> <span class='menu-name'></span></a></li>");

$menuItem.on("click", function () {
// Set focus back to the editor when the menu is dismissed. The command
// may additionally move focus elsewhere.
EditorManager.focusEditor();

menuItem._command.execute();
});
}

// Insert menu item
var $relativeElement = this._getRelativeMenuItem(relativeID);
var $relativeElement = this._getRelativeMenuItem(relativeID, position);
_insertInList($("li#" + StringUtils.jQueryIdEscape(this.id) + " > ul.dropdown-menu"),
$menuItem, position, $relativeElement);

Expand Down Expand Up @@ -427,8 +471,8 @@ define(function (require, exports, module) {
* @param {?string} position - constant defining the position of new the divider relative
* to other MenuItems. Default is LAST. (see Insertion position constants).
* @param {?string} relativeID - id of menuItem, sub-menu, or menu section that the new
* divider will be positioned relative to. Required when position is
* AFTER or BEFORE, ignored when position is FIRST or LAST.
* divider will be positioned relative to. Required for all position constants
* except FIRST and LAST
*
* @return {MenuItem} the newly created divider
*/
Expand Down Expand Up @@ -607,13 +651,14 @@ define(function (require, exports, module) {
_insertInList($menubar, $newMenu, position, $relativeElement);

// Install ESC key handling
PopUpManager.configurePopUp($popUp, closeAll);
PopUpManager.addPopUp($popUp, menu.close, false);

// todo error handling

return menu;
}


/**
* @constructor
* @extends {Menu}
Expand Down Expand Up @@ -645,7 +690,12 @@ define(function (require, exports, module) {
// insert into DOM
$("#context-menu-bar > ul").append($newMenu);

PopUpManager.configurePopUp($popUp, closeAll);
var self = this;
PopUpManager.addPopUp($popUp,
function () {
self.close();
},
false);
}
ContextMenu.prototype = new Menu();
ContextMenu.prototype.constructor = ContextMenu;
Expand Down Expand Up @@ -912,6 +962,14 @@ define(function (require, exports, module) {
$(window).contextmenu(function (e) {
e.preventDefault();
});

/*
* General menu event processing
*/
// Prevent clicks on top level menus and menu items from taking focus
$(window.document).on("mousedown", ".dropdown", function (e) {
e.preventDefault();
});

// Switch menus when the mouse enters an adjacent menu
// Only open the menu if another one has already been opened
Expand All @@ -934,6 +992,8 @@ define(function (require, exports, module) {
exports.AFTER = AFTER;
exports.LAST = LAST;
exports.FIRST = FIRST;
exports.FIRST_IN_SECTION = FIRST_IN_SECTION;
exports.LAST_IN_SECTION = LAST_IN_SECTION;
exports.DIVIDER = DIVIDER;
exports.getMenu = getMenu;
exports.getMenuItem = getMenuItem;
Expand Down
4 changes: 3 additions & 1 deletion src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ define(function (require, exports, module) {
ProjectManager.createNewItem(baseDir, suggestedName, false)
.pipe(deferred.resolve, deferred.reject, deferred.notify)
.always(function () { fileNewInProgress = false; })
.done(function (entry) { FileViewController.addToWorkingSetAndSelect(entry.fullPath); });
.done(function (entry) {
FileViewController.addToWorkingSetAndSelect(entry.fullPath, FileViewController.PROJECT_MANAGER);
});
};

deferred.done(createWithSuggestedName);
Expand Down
29 changes: 13 additions & 16 deletions src/editor/CodeHintManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,13 @@ define(function (require, exports, module) {
*/
CodeHintList.prototype.updateQueryFromCurPos = function () {
var pos = this.editor.getCursorPos(),
cursor = this.editor.indexFromPos(pos),
tagInfo = HTMLUtils.getTagInfo(this.editor, pos);


this.query = null;
if (tagInfo.position.tokenType === HTMLUtils.TAG_NAME) {
var text = this.editor.document.getText(),
start = text.lastIndexOf("<", cursor) + 1;
if (start <= cursor) {
this.query = text.slice(start, cursor);
} else {
this.query = null;
if (tagInfo.position.offset >= 0) {
this.query = tagInfo.tagName.slice(0, tagInfo.position.offset);
}
} else {
this.query = null;
}
};

Expand Down Expand Up @@ -387,11 +381,6 @@ define(function (require, exports, module) {
* @param {KeyboardEvent} event
*/
function handleKeyEvent(editor, event) {
// For now we only handle hints in html
if (editor.getModeForSelection() !== "html") {
return;
}

// Check for Control+Space or "<"
if (event.type === "keydown" && event.keyCode === 32 && event.ctrlKey) {
_showHint(editor);
Expand All @@ -405,7 +394,15 @@ define(function (require, exports, module) {
hintList.handleKeyEvent(editor, event);
}
}

/**
* Expose CodeHintList for unit testing
*/
function _getCodeHintList() {
return hintList;
}

// Define public API
exports.handleKeyEvent = handleKeyEvent;
exports.handleKeyEvent = handleKeyEvent;
exports._getCodeHintList = _getCodeHintList;
});
2 changes: 1 addition & 1 deletion src/editor/MultiRangeInlineEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ define(function (require, exports, module) {
// growing the overall width.
// This is a bit of a hack since it relies on knowing some detail about the innards of CodeMirror.
var lineSpace = this.hostEditor._getLineSpaceElement(),
minWidth = $(lineSpace).offset().left - this.$htmlContent.offset().left + $(lineSpace).width();
minWidth = $(lineSpace).offset().left - this.$htmlContent.offset().left + lineSpace.scrollWidth;
this.$htmlContent.css("min-width", minWidth + "px");
};

Expand Down
2 changes: 2 additions & 0 deletions src/language/HTMLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ define(function (require, exports, module) {
// pos has whitespace before it and non-whitespace after it, so use token after
ctx.pos = testPos;
ctx.token = testToken;
// Get the new offset from test token and subtract one for testPos adjustment
offset = _offsetInToken(ctx) - 1;
} else {
// next, see what's before pos
if (!_movePrevToken(ctx)) {
Expand Down
6 changes: 4 additions & 2 deletions src/project/FileViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ define(function (require, exports, module) {
* Opens the specified document if it's not already open, adds it to the working set,
* and selects it in the WorkingSetView
* @param {!fullPath}
* @param {?String} selectIn - specify either WORING_SET_VIEW or PROJECT_MANAGER.
* Default is WORING_SET_VIEW.
* @return {!$.Promise}
*/
function addToWorkingSetAndSelect(fullPath) {
function addToWorkingSetAndSelect(fullPath, selectIn) {
var result = new $.Deferred(),
promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath});

Expand All @@ -179,7 +181,7 @@ define(function (require, exports, module) {
promise.done(function (doc) {
// FILE_ADD_TO_WORKING_SET command sets the current document. Update the
// selection focus and trigger documentSelectionFocusChange event
_fileSelectionFocus = WORKING_SET_VIEW;
_fileSelectionFocus = selectIn ? selectIn : WORKING_SET_VIEW;
_selectCurrentDocument();

result.resolve(doc);
Expand Down
Loading

0 comments on commit 4d87891

Please sign in to comment.