mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Add specs
This commit is contained in:
@@ -4,49 +4,15 @@ fs = require 'fs-plus'
|
||||
{specificity} = require 'clear-cut'
|
||||
PEG = require 'pegjs'
|
||||
|
||||
nextBindingSetIndex = 0
|
||||
|
||||
### Internal ###
|
||||
|
||||
module.exports =
|
||||
class BindingSet
|
||||
@parser: null
|
||||
|
||||
selector: null
|
||||
commandsByKeystroke: null
|
||||
parser: null
|
||||
name: null
|
||||
@nextBindingSetIndex: 0
|
||||
|
||||
constructor: (selector, commandsByKeystroke, @name) ->
|
||||
@index = nextBindingSetIndex++
|
||||
@index = BindingSet.nextBindingSetIndex++
|
||||
keystrokePattern = fs.readFileSync(require.resolve('./keystroke-pattern.pegjs'), 'utf8')
|
||||
BindingSet.parser ?= PEG.buildParser(keystrokePattern)
|
||||
@specificity = specificity(selector)
|
||||
@selector = selector.replace(/!important/g, '')
|
||||
@commandsByKeystroke = @normalizeCommandsByKeystroke(commandsByKeystroke)
|
||||
|
||||
# Private:
|
||||
getName: ->
|
||||
@name
|
||||
|
||||
# Private:
|
||||
getSelector: ->
|
||||
@selector
|
||||
|
||||
# Private:
|
||||
getCommandsByKeystroke: ->
|
||||
@commandsByKeystroke
|
||||
|
||||
normalizeCommandsByKeystroke: (commandsByKeystroke) ->
|
||||
normalizedCommandsByKeystroke = {}
|
||||
for keystroke, command of commandsByKeystroke
|
||||
normalizedCommandsByKeystroke[@normalizeKeystroke(keystroke)] = command
|
||||
normalizedCommandsByKeystroke
|
||||
|
||||
normalizeKeystroke: (keystroke) ->
|
||||
normalizedKeystroke = keystroke.split(/\s+/).map (keystroke) =>
|
||||
keys = BindingSet.parser.parse(keystroke)
|
||||
modifiers = keys[0...-1]
|
||||
modifiers.sort()
|
||||
[modifiers..., _.last(keys)].join('-')
|
||||
normalizedKeystroke.join(' ')
|
||||
|
||||
Reference in New Issue
Block a user