1 utils = require 'utils'
17 constructor: (@window) ->
26 enterHintsMode: (@markers, @cb) ->
29 # TODO: This function should probably remove
30 # hint markers (if they are present) as well
33 @markers = @cb = undefined
35 handleKeyDown: (keyboardEvent, keyStr) ->
36 if @mode == MODE_NORMAL || keyStr == 'Esc'
37 result = maybeCommand @keys.concat([keyStr])
38 else if !keyboardEvent.ctrlKey and !keyboardEvent.metaKey
39 if @mode == MODE_HINTS
40 hintChars = getPref('hint_chars').toLowerCase() or getDefaultPref('hint_chars')
41 result = hintChars.search(regexpEscape(keyStr)) > -1
49 handleKeyPress: (keyboardEvent) ->
50 lastKeyStr = if @keys.length > 0 then @keys[@keys.length - 1] else undefined
51 if @mode == MODE_NORMAL or lastKeyStr == 'Esc'
52 if command = findCommand @keys
56 else if !keyboardEvent.ctrlKey and !keyboardEvent.metaKey
58 if @mode == MODE_HINTS
59 hintCharHandler @, lastKeyStr, keyboardEvent.charCode
64 findCommand = (keys) ->
65 for i in [0...keys.length]
66 seq = keys.slice(i).join(',')
67 if com = commands[seq]
68 if not isCommandDisabled(seq)
73 maybeCommand = (keys) ->
74 for i in [0...keys.length]
75 sequence = keys.slice(i).join(',')
76 for seq, com of commands
77 if seq.indexOf(sequence) == 0
78 return not isCommandDisabled(seq)