mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Check selectors using webkitMatchesSelector
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user