1 utils = require 'utils'
2 { modes } = require 'modes'
3 { isEscCommandKey } = require 'commands'
6 constructor: (@window) ->
10 enterMode: (mode, args) ->
11 # `args` is an array of arguments to be passed to the mode's `onEnter` method
13 throw new Error("Not a valid VimFx mode to enter: #{ mode }")
17 modes[@mode].onLeave(@, @storage[@mode], args)
21 modes[@mode].onEnter(@, @storage[@mode] ?= {}, args)
23 onInput: (keyStr, event) ->
24 isEditable = utils.isElementEditable(event.originalTarget)
26 if isEditable and not isEscCommandKey(keyStr)
31 suppress = modes[@mode]?.onInput(@, @storage[@mode], keyStr, event)
33 # Esc key is not suppressed, and passed to the browser in `normal` mode.
34 # Here we compare against the mode that was active before the key was
35 # processed because processing the command may change the mode.
37 # Not suppressing Esc allows for stopping the loading of the page as well as
38 # closing many custom dialogs (and perhaps other things -- Esc is a very
39 # commonly used key). There are two reasons we might suppress it in other
40 # modes. If some custom dialog of a website is open, we should be able to
41 # cancel hint markers on it without closing it. Secondly, otherwise
42 # cancelling hint markers on google causes its search bar to be focused.
43 if oldMode == 'normal' and keyStr == 'Esc'