aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode_passkeys.coffee
blob: 112e14edfec2c86b344b48788ea2f350bc78da45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class PassKeysMode extends Mode
  constructor: ->
    super
      name: "passkeys"
      trackState: true
      keydown: (event) => @handleKeyChar KeyboardUtils.getKeyChar event
      keypress: (event) => @handleKeyChar String.fromCharCode event.charCode
      keyup: (event) => @handleKeyChar String.fromCharCode event.charCode

  # Decide whether this event should be passed to the underlying page.  Keystrokes are *never* considered
  # passKeys if the keyQueue is not empty.  So, for example, if 't' is a passKey, then 'gt' and '99t' will
  # neverthless be handled by vimium.
  handleKeyChar: (keyChar) ->
    return @stopBubblingAndTrue if keyChar and not @keyQueue and 0 <= @passKeys.indexOf keyChar
    @continueBubbling

  configure: (request) ->
    @keyQueue = request.keyQueue if request.keyQueue?

  chooseBadge: (badge) ->
    badge.badge ||= "P" if @passKeys and not @keyQueue

root = exports ? window
root.PassKeysMode = PassKeysMode