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