1 utils = require 'utils'
16 constructor: (@window) ->
25 enterHintsMode: (@markers, @cb) ->
28 # TODO: This function should probably remove
29 # hint markers (if they are present) as well
32 @markers = @cb = undefined
34 handleKeyDown: (keyboardEvent, keyStr) ->
35 if @mode == MODE_NORMAL || keyStr == 'Esc'
36 result = maybeCommand @keys.concat([keyStr])
37 else if !keyboardEvent.ctrlKey and !keyboardEvent.metaKey
38 if @mode == MODE_HINTS
39 result = utils.getHintChars().search(regexpEscape(keyStr)) > -1
47 handleKeyPress: (keyboardEvent) ->
48 lastKeyStr = if @keys.length > 0 then @keys[@keys.length - 1] else undefined
49 if @mode == MODE_NORMAL or lastKeyStr == 'Esc'
50 if command = findCommand @keys
54 else if !keyboardEvent.ctrlKey and !keyboardEvent.metaKey
56 if @mode == MODE_HINTS
57 hintCharHandler @, lastKeyStr, keyboardEvent.charCode
62 findCommand = (keys) ->
63 for i in [0...keys.length]
64 seq = keys.slice(i).join(',')
65 if com = commands[seq]
66 if not isCommandDisabled(seq)
71 maybeCommand = (keys) ->
72 for i in [0...keys.length]
73 sequence = keys.slice(i).join(',')
74 for seq, com of commands
75 if seq.indexOf(sequence) == 0
76 return not isCommandDisabled(seq)