Prevent menus from stealing focus and enables indent/undent from menus #672
Changes from all commits
3df6b61
3b44f2f
e90f798
f5193ef
49a89ad
75d5d55
7915881
bc29d87
2b3a283
ae5cdd6
2e3d80e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -41,7 +41,6 @@ define(function (require, exports, module) { | ||
"menu-edit-find-next": Commands.EDIT_FIND_NEXT, | "menu-edit-find-next": Commands.EDIT_FIND_NEXT, | ||
"menu-edit-find-previous": Commands.EDIT_FIND_PREVIOUS, | "menu-edit-find-previous": Commands.EDIT_FIND_PREVIOUS, | ||
"menu-edit-replace": Commands.EDIT_REPLACE, | "menu-edit-replace": Commands.EDIT_REPLACE, | ||
|
|||
|
|
||
// View | // View | ||
"menu-view-hide-sidebar": Commands.VIEW_HIDE_SIDEBAR, | "menu-view-hide-sidebar": Commands.VIEW_HIDE_SIDEBAR, | ||
|
@@ -69,10 +68,8 @@ define(function (require, exports, module) { | ||
|
|
||
function createExecFunc(commandStr) { | function createExecFunc(commandStr) { | ||
return function () { | return function () { | ||
// TODO TY: should flash menu here | // TODO TY: should flash menu here on Mac | ||
//console.log(commandStr); | //console.log(commandStr); | ||
|
|||
EditorManager.focusEditor(); | |||
CommandManager.execute(commandStr); | CommandManager.execute(commandStr); | ||
}; | }; | ||
} | } | ||
|
@@ -106,11 +103,22 @@ define(function (require, exports, module) { | ||
shortcut = keyCmd.replace(/-/g, "+"); | shortcut = keyCmd.replace(/-/g, "+"); | ||
} | } | ||
|
|
||
$("#" + menuID).append("<span class='menu-shortcut'>" + shortcut + "</span>"); | var $menu = $("#" + menuID); | ||
// Some commands have multiple key commands. Only add the first one. | |||
if ($menu.find(".menu-shortcut").length === 0) { | |||
$menu.append("<span class='menu-shortcut'>" + shortcut + "</span>"); | |||
} | |||
} | } | ||
} | } | ||
} | } | ||
|
|
||
// Prevent clicks on the top-level menu bar from taking focus | |||
// Note, bootstrap handles this already for the menu drop downs | |||
$("#main-toolbar .dropdown").mousedown(function (e) { | |||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to add a note here that the only reason we don't also have to do this for top-level menu bar items is (I think) because Bootstrap already takes care of it in bootstrap-dropdown.js. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a note. Interestingly I don't see code that does this in bootstrap-dropdown.js that does this directly. The $.fn.dropdown returns false... I am not sure what that does or if it is related to focus. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the "return false" in that click handler that does it -- that's an old-school equivalent to preventDefault(). |
|||
e.preventDefault(); | |||
}); | |||
|
|||
|
|||
|
|
||
// Other debug menu items | // Other debug menu items | ||
// $("#menu-debug-wordwrap").click(function() { | // $("#menu-debug-wordwrap").click(function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the code can exit the loop after the first shortcut string is added. Or at least, only build the "shortcut" string once you've determined that it's the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's the idea -- if there's more than one shortcut bound to the same menu item, we don't want to list all the shortcuts in the menu UI... just the first one we come across. There's no
break
or anything, so it won't actually exit the loop; it just won't add another shortcut label to the UI if one is already present.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, Ty, this does raise one issue: if there's more than one shortcut, the one that wins is completely arbitrary, not the first one listed in the code in brackets.js (because we're iterating a map here, not an ordered list).
Maybe because of this, for now we should print a warning to the console whenever a 2nd shortcut for the same menu is encountered? I think with the removal of the Tab bindings above, we no longer have any commands that would hit this caseat the moment...