 
   # This tests whether there is a mapping of keyChar in the current key state (and accounts for pass keys).
   isMappedKey: (keyChar) ->
+    # TODO(philc): tweak the generated js.
     (mapping for mapping in @keyState when keyChar of mapping)[0]? and not @isPassKey keyChar
 
   # This tests whether keyChar is a digit (and accounts for pass keys).
   isCountKey: (keyChar) ->
-    keyChar and (if 0 < @countPrefix then '0' else '1') <= keyChar <= '9' and not @isPassKey keyChar
+    keyChar and (if @countPrefix > 0 then '0' else '1') <= keyChar <= '9' and not @isPassKey keyChar
 
   # Keystrokes are *never* considered pass keys if the user has begun entering a command.  So, for example, if
   # 't' is a passKey, then the "t"-s of 'gt' and '99t' are neverthless handled as regular keys.

            @suppressEvent
          else
            @continueBubbling

  onKeydown: (event) ->
    keyChar = KeyboardUtils.getKeyCharString event

# consists of a (non-empty) list of such mappings.

class KeyHandlerMode extends (window.Mode || global.Mode)
  setKeyMapping: (@keyMapping) -> @reset(); return
  setPassKeys: (@passKeys) -> @reset(); return

  # Only for tests.
  setCommandHandler: (@commandHandler) ->

  # Reset the key state, optionally retaining the count provided.
  reset: (@countPrefix = 0) ->
    @keyState = [@keyMapping]
    return

  init: (options) ->
    args = extend(options, keydown: @onKeydown.bind(this))
    super.init(args)

    @commandHandler = options.commandHandler || (->)
    @setKeyMapping options.keyMapping || {}

    if options.exitOnEscape
      # If we're part way through a command's key sequence, then a first Escape should reset the key state,
