1 utils = require 'utils'
2 { mode_hints } = require 'mode-hints/mode-hints'
3 { updateToolbarButton } = require 'button'
4 { searchForMatchingCommand
7 , findStorage } = require 'commands'
12 onEnter: (vim, storage) ->
14 storage.commands ?= {}
16 onLeave: (vim, storage) ->
17 storage.keys.length = 0
19 onInput: (vim, storage, keyStr, event) ->
20 isEditable = utils.isElementEditable(event.originalTarget)
21 autoInsertMode = isEditable or vim.rootWindow.TabView.isVisible()
23 if autoInsertMode and not isEscCommandKey(keyStr)
26 storage.keys.push(keyStr)
28 { match, exact, command } = searchForMatchingCommand(storage.keys)
32 command.func(vim, event)
33 storage.keys.length = 0
35 # Esc key is not suppressed, and passed to the browser in normal mode.
37 # - It allows for stopping the loading of the page.
38 # - It allows for closing many custom dialogs (and perhaps other things
39 # -- Esc is a very commonly used key).
40 # - It is not passed if Esc is used for `command_Esc` and we’re blurring
41 # an element. That allows for blurring an input in a custom dialog
42 # without closing the dialog too.
43 # - There are two reasons we might suppress it in other modes. If some
44 # custom dialog of a website is open, we should be able to cancel hint
45 # markers on it without closing it. Secondly, otherwise cancelling hint
46 # markers on Google causes its search bar to be focused.
47 if keyStr == 'Esc' and not autoInsertMode
53 storage.keys.length = 0
58 updateToolbarButton(vim.rootWindow, {insertMode: true})
60 updateToolbarButton(vim.rootWindow, {insertMode: false})
61 utils.blurActiveElement(vim.window)
62 onInput: (vim, storage, keyStr) ->
63 if isEscCommandKey(keyStr)
64 vim.enterMode('normal')
71 findBar = vim.rootWindow.gBrowser.getFindBar()
72 findStorage.lastSearchString = findBar._findField.value
74 onInput: (vim, storage, keyStr) ->
75 findBar = vim.rootWindow.gBrowser.getFindBar()
76 if isEscCommandKey(keyStr) or keyStr == 'Return'
81 modes['hints'] = mode_hints