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 hintChars = getPref('hint_chars').toLowerCase()
40 result = hintChars.search(regexpEscape(keyStr)) > -1
48 handleKeyPress: (keyboardEvent) ->
49 lastKeyStr = if @keys.length > 0 then @keys[@keys.length - 1] else undefined
50 if @mode == MODE_NORMAL or lastKeyStr == 'Esc'
51 if command = findCommand @keys
55 else if !keyboardEvent.ctrlKey and !keyboardEvent.metaKey
57 if @mode == MODE_HINTS
58 hintCharHandler @, lastKeyStr, keyboardEvent.charCode
63 findCommand = (keys) ->
64 for i in [0...keys.length]
65 seq = keys.slice(i).join(',')
66 if com = commands[seq]
67 if not isCommandDisabled(seq)
72 maybeCommand = (keys) ->
73 for i in [0...keys.length]
74 sequence = keys.slice(i).join(',')
75 for seq, com of commands
76 if seq.indexOf(sequence) == 0
77 return not isCommandDisabled(seq)