diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index 0ae3f26d8..51bc745a3 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -27,11 +27,27 @@ class MenuManager @merge(@template, item) for item in items @update() + # Private: Should the binding for the given selector be included in the menu + # commands. + # + # * selector: A String selector to check. + # + # Returns true to include the selector, false otherwise. + includeSelector: (selector) -> + unless @testEditor? + @testEditor = document.createElement('div') + @testEditor.classList.add('editor') + testBody = document.createElement('body') + testBody.classList.add(document.body.classList.toString().split(' ')...) + testBody.appendChild(@testEditor) + + document.body.webkitMatchesSelector(selector) or @testEditor.webkitMatchesSelector(selector) + # Public: Refreshes the currently visible menu. update: -> keystrokesByCommand = {} - selectors = ['body', ".platform-#{process.platform}", '.editor', '.editor:not(.mini)'] - for binding in atom.keymap.getKeyBindings() when binding.selector in selectors + for binding in atom.keymap.getKeyBindings() when @includeSelector(binding.selector) + console.log binding.selector keystrokesByCommand[binding.command] ?= [] keystrokesByCommand[binding.command].push binding.keystroke @sendToBrowserProcess(@template, keystrokesByCommand) @@ -40,8 +56,8 @@ class MenuManager loadPlatformItems: -> menusDirPath = path.join(@resourcePath, 'menus') platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json']) - data = CSON.readFileSync(platformMenuPath) - @add(data.menu) + {menu} = CSON.readFileSync(platformMenuPath) + @add(menu) # Private: Merges an item in a submenu aware way such that new items are always # appended to the bottom of existing menus where possible.