]> git.gir.st - VimFx.git/blob - extension/packages/modes.coffee
Polish translation update
[VimFx.git] / extension / packages / modes.coffee
1 utils = require 'utils'
2 { mode_hints } = require 'mode-hints/mode-hints'
3 { updateToolbarButton } = require 'button'
4 { searchForMatchingCommand
5 , isEscCommandKey
6 , isReturnCommandKey
7 , findStorage } = require 'commands'
8
9 { interfaces: Ci } = Components
10
11 XULDocument = Ci.nsIDOMXULDocument
12
13 modes = {}
14
15 modes['normal'] =
16 onEnter: (vim, storage) ->
17 storage.keys ?= []
18 storage.commands ?= {}
19
20 onLeave: (vim, storage) ->
21 storage.keys.length = 0
22
23 onInput: (vim, storage, keyStr, event) ->
24 isEditable = utils.isElementEditable(event.originalTarget)
25 autoInsertMode = isEditable or vim.rootWindow.TabView.isVisible()
26
27 if autoInsertMode and not isEscCommandKey(keyStr)
28 return false
29
30 storage.keys.push(keyStr)
31
32 { match, exact, command } = searchForMatchingCommand(storage.keys)
33
34 if match
35 if exact
36 command.func(vim, event)
37 storage.keys.length = 0
38
39 # Esc key is not suppressed, and passed to the browser in normal mode.
40 #
41 # - It allows for stopping the loading of the page.
42 # - It allows for closing many custom dialogs (and perhaps other things
43 # -- Esc is a very commonly used key).
44 # - It is not passed if Esc is used for `command_Esc` and we’re blurring
45 # an element. That allows for blurring an input in a custom dialog
46 # without closing the dialog too.
47 # - There are two reasons we might suppress it in other modes. If some
48 # custom dialog of a website is open, we should be able to cancel hint
49 # markers on it without closing it. Secondly, otherwise cancelling hint
50 # markers on Google causes its search bar to be focused.
51 # - It may only be suppressed in web pages, not in browser chrome. That
52 # allows for reseting the location bar when blurring it, and closing
53 # dialogs such as the “bookmark this page” dialog (<c-d>).
54 document = event.originalTarget.ownerDocument
55 inBrowserChrome = (document instanceof XULDocument)
56 if keyStr == 'Esc' and (not autoInsertMode or inBrowserChrome)
57 return false
58
59 return true
60
61 else
62 storage.keys.length = 0
63 return false
64
65 modes['insert'] =
66 onEnter: (vim) ->
67 updateToolbarButton(vim.rootWindow, {insertMode: true})
68 onLeave: (vim) ->
69 updateToolbarButton(vim.rootWindow, {insertMode: false})
70 utils.blurActiveElement(vim.window)
71 onInput: (vim, storage, keyStr) ->
72 if isEscCommandKey(keyStr)
73 vim.enterMode('normal')
74 return true
75
76 modes['find'] =
77 onEnter: ->
78
79 onLeave: (vim) ->
80 findBar = vim.rootWindow.gBrowser.getFindBar()
81 findStorage.lastSearchString = findBar._findField.value
82
83 onInput: (vim, storage, keyStr) ->
84 findBar = vim.rootWindow.gBrowser.getFindBar()
85 if isEscCommandKey(keyStr) or keyStr == 'Return'
86 findBar.close()
87 return true
88 return false
89
90 modes['hints'] = mode_hints
91
92 exports.modes = modes
Imprint / Impressum