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, count } = searchForMatchingCommand(storage.keys)
32 command.func(vim, event, count)
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 unless /\d/.test(keyStr)
59 updateToolbarButton(vim.rootWindow, {insertMode: true})
61 updateToolbarButton(vim.rootWindow, {insertMode: false})
62 utils.blurActiveElement(vim.window)
63 onInput: (vim, storage, keyStr) ->
64 if isEscCommandKey(keyStr)
65 vim.enterMode('normal')
72 findBar = vim.rootWindow.gBrowser.getFindBar()
73 findStorage.lastSearchString = findBar._findField.value
75 onInput: (vim, storage, keyStr) ->
76 findBar = vim.rootWindow.gBrowser.getFindBar()
77 if isEscCommandKey(keyStr) or keyStr == 'Return'
82 modes['hints'] = mode_hints