]> git.gir.st - VimFx.git/blob - extension/lib/commands.coffee
Merge pull request #451 from lydell/hints
[VimFx.git] / extension / lib / commands.coffee
1 ###
2 # Copyright Anton Khodakivskiy 2012, 2013, 2014.
3 # Copyright Simon Lydell 2013, 2014.
4 # Copyright Wang Zhuochun 2013, 2014.
5 #
6 # This file is part of VimFx.
7 #
8 # VimFx is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # VimFx is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
20 ###
21
22 notation = require('vim-like-key-notation')
23 { Marker } = require('./marker')
24 legacy = require('./legacy')
25 utils = require('./utils')
26 help = require('./help')
27 _ = require('./l10n')
28 { getPref
29 , setPref
30 , isPrefSet } = require('./prefs')
31
32 { isProperLink, isTextInputElement, isContentEditable } = utils
33
34 { classes: Cc, interfaces: Ci, utils: Cu } = Components
35
36 XULDocument = Ci.nsIDOMXULDocument
37
38 # “Selecting an element” means “focusing and selecting the text, if any, of an
39 # element”.
40
41 # Select the Address Bar.
42 command_focus = (vim) ->
43 # This function works even if the Address Bar has been removed.
44 vim.rootWindow.focusAndSelectUrlBar()
45
46 # Select the Search Bar.
47 command_focus_search = (vim) ->
48 # The `.webSearch()` method opens a search engine in a tab if the Search Bar
49 # has been removed. Therefore we first check if it exists.
50 if vim.rootWindow.BrowserSearch.searchBar
51 vim.rootWindow.BrowserSearch.webSearch()
52
53 helper_paste = (vim) ->
54 url = vim.rootWindow.readFromClipboard()
55 postData = null
56 if not utils.isURL(url) and submission = utils.browserSearchSubmission(url)
57 url = submission.uri.spec
58 { postData } = submission
59 return {url, postData}
60
61 # Go to or search for the contents of the system clipboard.
62 command_paste = (vim) ->
63 { url, postData } = helper_paste(vim)
64 vim.rootWindow.gBrowser.loadURIWithFlags(url, null, null, null, postData)
65
66 # Go to or search for the contents of the system clipboard in a new tab.
67 command_paste_tab = (vim) ->
68 { url, postData } = helper_paste(vim)
69 vim.rootWindow.gBrowser.selectedTab =
70 vim.rootWindow.gBrowser.addTab(url, null, null, postData, null, false)
71
72 # Copy the current URL to the system clipboard.
73 command_yank = (vim) ->
74 utils.writeToClipboard(vim.window.location.href)
75
76 # Reload the current tab, possibly from cache.
77 command_reload = (vim) ->
78 vim.rootWindow.BrowserReload()
79
80 # Reload the current tab, skipping cache.
81 command_reload_force = (vim) ->
82 vim.rootWindow.BrowserReloadSkipCache()
83
84 # Reload all tabs, possibly from cache.
85 command_reload_all = (vim) ->
86 vim.rootWindow.gBrowser.reloadAllTabs()
87
88 # Reload all tabs, skipping cache.
89 command_reload_all_force = (vim) ->
90 for tab in vim.rootWindow.gBrowser.visibleTabs
91 window = tab.linkedBrowser.contentWindow
92 window.location.reload(true)
93
94 # Stop loading the current tab.
95 command_stop = (vim) ->
96 vim.window.stop()
97
98 # Stop loading all tabs.
99 command_stop_all = (vim) ->
100 for tab in vim.rootWindow.gBrowser.visibleTabs
101 window = tab.linkedBrowser.contentWindow
102 window.stop()
103
104 # Scroll to the top of the page.
105 command_scroll_to_top = (vim) ->
106 vim.rootWindow.goDoCommand('cmd_scrollTop')
107
108 # Scroll to the bottom of the page.
109 command_scroll_to_bottom = (vim) ->
110 vim.rootWindow.goDoCommand('cmd_scrollBottom')
111
112 # Scroll down a bit.
113 command_scroll_down = (vim, event, count) ->
114 step = getPref('scroll_step_lines') * count
115 utils.simulateWheel(vim.window, 0, +step, utils.WHEEL_MODE_LINE)
116
117 # Scroll up a bit.
118 command_scroll_up = (vim, event, count) ->
119 step = getPref('scroll_step_lines') * count
120 utils.simulateWheel(vim.window, 0, -step, utils.WHEEL_MODE_LINE)
121
122 # Scroll left a bit.
123 command_scroll_left = (vim, event, count) ->
124 step = getPref('scroll_step_lines') * count
125 utils.simulateWheel(vim.window, -step, 0, utils.WHEEL_MODE_LINE)
126
127 # Scroll right a bit.
128 command_scroll_right = (vim, event, count) ->
129 step = getPref('scroll_step_lines') * count
130 utils.simulateWheel(vim.window, +step, 0, utils.WHEEL_MODE_LINE)
131
132 # Scroll down half a page.
133 command_scroll_half_page_down = (vim, event, count) ->
134 utils.simulateWheel(vim.window, 0, +0.5 * count, utils.WHEEL_MODE_PAGE)
135
136 # Scroll up half a page.
137 command_scroll_half_page_up = (vim, event, count) ->
138 utils.simulateWheel(vim.window, 0, -0.5 * count, utils.WHEEL_MODE_PAGE)
139
140 # Scroll down full a page.
141 command_scroll_page_down = (vim, event, count) ->
142 utils.simulateWheel(vim.window, 0, +1 * count, utils.WHEEL_MODE_PAGE)
143
144 # Scroll up full a page.
145 command_scroll_page_up = (vim, event, count) ->
146 utils.simulateWheel(vim.window, 0, -1 * count, utils.WHEEL_MODE_PAGE)
147
148 # Open a new tab and select the Address Bar.
149 command_open_tab = (vim) ->
150 vim.rootWindow.BrowserOpenTab()
151
152 absoluteTabIndex = (relativeIndex, gBrowser) ->
153 tabs = gBrowser.visibleTabs
154 { selectedTab } = gBrowser
155
156 currentIndex = tabs.indexOf(selectedTab)
157 absoluteIndex = currentIndex + relativeIndex
158 numTabs = tabs.length
159
160 wrap = (Math.abs(relativeIndex) == 1)
161 if wrap
162 absoluteIndex %%= numTabs
163 else
164 absoluteIndex = Math.max(0, absoluteIndex)
165 absoluteIndex = Math.min(absoluteIndex, numTabs - 1)
166
167 return absoluteIndex
168
169 helper_switch_tab = (direction, vim, event, count) ->
170 { gBrowser } = vim.rootWindow
171 gBrowser.selectTabAtIndex(absoluteTabIndex(direction * count, gBrowser))
172
173 # Switch to the previous tab.
174 command_tab_prev = helper_switch_tab.bind(undefined, -1)
175
176 # Switch to the next tab.
177 command_tab_next = helper_switch_tab.bind(undefined, +1)
178
179 helper_move_tab = (direction, vim, event, count) ->
180 { gBrowser } = vim.rootWindow
181 { selectedTab } = gBrowser
182 { pinned } = selectedTab
183
184 index = absoluteTabIndex(direction * count, gBrowser)
185
186 if index < gBrowser._numPinnedTabs
187 gBrowser.pinTab(selectedTab) unless pinned
188 else
189 gBrowser.unpinTab(selectedTab) if pinned
190
191 gBrowser.moveTabTo(selectedTab, index)
192
193 # Move the current tab backward.
194 command_tab_move_left = helper_move_tab.bind(undefined, -1)
195
196 # Move the current tab forward.
197 command_tab_move_right = helper_move_tab.bind(undefined, +1)
198
199 # Load the home page.
200 command_home = (vim) ->
201 vim.rootWindow.BrowserHome()
202
203 # Switch to the first tab.
204 command_tab_first = (vim) ->
205 vim.rootWindow.gBrowser.selectTabAtIndex(0)
206
207 # Switch to the first non-pinned tab.
208 command_tab_first_non_pinned = (vim) ->
209 firstNonPinned = vim.rootWindow.gBrowser._numPinnedTabs
210 vim.rootWindow.gBrowser.selectTabAtIndex(firstNonPinned)
211
212 # Switch to the last tab.
213 command_tab_last = (vim) ->
214 vim.rootWindow.gBrowser.selectTabAtIndex(-1)
215
216 # Toggle Pin Tab.
217 command_toggle_pin_tab = (vim) ->
218 currentTab = vim.rootWindow.gBrowser.selectedTab
219
220 if currentTab.pinned
221 vim.rootWindow.gBrowser.unpinTab(currentTab)
222 else
223 vim.rootWindow.gBrowser.pinTab(currentTab)
224
225 # Duplicate current tab.
226 command_duplicate_tab = (vim) ->
227 { gBrowser } = vim.rootWindow
228 gBrowser.duplicateTab(gBrowser.selectedTab)
229
230 # Close all tabs from current to the end.
231 command_close_tabs_to_end = (vim) ->
232 { gBrowser } = vim.rootWindow
233 gBrowser.removeTabsToTheEndFrom(gBrowser.selectedTab)
234
235 # Close all tabs except the current.
236 command_close_other_tabs = (vim) ->
237 { gBrowser } = vim.rootWindow
238 gBrowser.removeAllTabsBut(gBrowser.selectedTab)
239
240 # Close current tab.
241 command_close_tab = (vim, event, count) ->
242 { gBrowser } = vim.rootWindow
243 return if gBrowser.selectedTab.pinned
244 currentIndex = gBrowser.visibleTabs.indexOf(gBrowser.selectedTab)
245 for tab in gBrowser.visibleTabs[currentIndex...(currentIndex + count)]
246 gBrowser.removeTab(tab)
247
248 # Restore last closed tab.
249 command_restore_tab = (vim, event, count) ->
250 vim.rootWindow.undoCloseTab() for [1..count]
251
252 # Combine links with the same href.
253 combine = (hrefs, marker) ->
254 if marker.type == 'link'
255 { href } = marker.element
256 if href of hrefs
257 parent = hrefs[href]
258 marker.parent = parent
259 parent.weight += marker.weight
260 parent.numChildren++
261 else
262 hrefs[href] = marker
263 return marker
264
265 # Follow links, focus text inputs and click buttons with hint markers.
266 command_follow = (vim, event, count) ->
267 hrefs = {}
268 filter = (element, getElementShape) ->
269 document = element.ownerDocument
270 isXUL = (document instanceof XULDocument)
271 semantic = true
272 switch
273 when isProperLink(element)
274 type = 'link'
275 when isTextInputElement(element) or isContentEditable(element)
276 type = 'text'
277 when element.tabIndex > -1 and
278 not (isXUL and element.nodeName.endsWith('box'))
279 type = 'clickable'
280 unless isXUL or element.nodeName in ['A', 'INPUT', 'BUTTON']
281 semantic = false
282 when element != vim.state.largestScrollableElement and
283 vim.state.scrollableElements.has(element)
284 type = 'scrollable'
285 when element.hasAttribute('onclick') or
286 element.hasAttribute('onmousedown') or
287 element.hasAttribute('onmouseup') or
288 element.hasAttribute('oncommand') or
289 element.getAttribute('role') in ['link', 'button'] or
290 # Twitter special-case.
291 element.classList.contains('js-new-tweets-bar')
292 type = 'clickable'
293 semantic = false
294 # Putting markers on `<label>` elements is generally redundant, because
295 # its `<input>` gets one. However, some sites hide the actual `<input>`
296 # but keeps the `<label>` to click, either for styling purposes or to keep
297 # the `<input>` hidden until it is used. In those cases we should add a
298 # marker for the `<label>`.
299 when element.nodeName == 'LABEL'
300 if element.htmlFor
301 input = document.getElementById(element.htmlFor)
302 if input and not getElementShape(input)
303 type = 'clickable'
304 # Elements that have “button” somewhere in the class might be clickable,
305 # unless they contain a real link or button in which case they likely are
306 # “button-wrapper”s. (`<SVG element>.className` is not a string!)
307 when not isXUL and typeof element.className == 'string' and
308 element.className.toLowerCase().contains('button')
309 unless element.querySelector('a, button')
310 type = 'clickable'
311 semantic = false
312 # When viewing an image it should get a marker to toggle zoom.
313 when document.body?.childElementCount == 1 and
314 element.nodeName == 'IMG' and
315 (element.classList.contains('overflowing') or
316 element.classList.contains('shrinkToFit'))
317 type = 'clickable'
318 return unless type
319 return unless shape = getElementShape(element)
320 return combine(hrefs, new Marker(element, shape, {semantic, type}))
321
322 callback = (marker) ->
323 { element } = marker
324 element.focus()
325 last = (count == 1)
326 if not last and marker.type == 'link'
327 utils.openTab(vim.rootWindow, element.href, {
328 inBackground: true
329 relatedToCurrent: true
330 })
331 else
332 if element.target == '_blank'
333 targetReset = element.target
334 element.target = ''
335 utils.simulateClick(element)
336 element.target = targetReset if targetReset
337 count--
338 return (not last and marker.type != 'text')
339
340 vim.enterMode('hints', filter, callback)
341
342 # Like command_follow but multiple times.
343 command_follow_multiple = (vim, event) ->
344 command_follow(vim, event, Infinity)
345
346 # Follow links in a new background tab with hint markers.
347 command_follow_in_tab = (vim, event, count, inBackground = true) ->
348 hrefs = {}
349 filter = (element, getElementShape) ->
350 return unless isProperLink(element)
351 return unless shape = getElementShape(element)
352 return combine(hrefs, new Marker(element, shape, {semantic: true}))
353
354 callback = (marker) ->
355 last = (count == 1)
356 utils.openTab(vim.rootWindow, marker.element.href, {
357 inBackground: if last then inBackground else true
358 relatedToCurrent: true
359 })
360 count--
361 return not last
362
363 vim.enterMode('hints', filter, callback)
364
365 # Follow links in a new foreground tab with hint markers.
366 command_follow_in_focused_tab = (vim, event, count) ->
367 command_follow_in_tab(vim, event, count, false)
368
369 # Copy the URL or text of a markable element to the system clipboard.
370 command_marker_yank = (vim) ->
371 hrefs = {}
372 filter = (element, getElementShape) ->
373 type = switch
374 when isProperLink(element) then 'link'
375 when isTextInputElement(element) then 'textInput'
376 when isContentEditable(element) then 'contenteditable'
377 return unless type
378 return unless shape = getElementShape(element)
379 return combine(hrefs, new Marker(element, shape, {semantic: true, type}))
380
381 callback = (marker) ->
382 { element } = marker
383 text = switch marker.type
384 when 'link' then element.href
385 when 'textInput' then element.value
386 when 'contenteditable' then element.textContent
387 utils.writeToClipboard(text)
388
389 vim.enterMode('hints', filter, callback)
390
391 # Focus element with hint markers.
392 command_marker_focus = (vim) ->
393 filter = (element, getElementShape) ->
394 type = switch
395 when element.tabIndex > -1
396 'focusable'
397 when element != vim.state.largestScrollableElement and
398 vim.state.scrollableElements.has(element)
399 'scrollable'
400 return unless type
401 return unless shape = getElementShape(element)
402 return new Marker(element, shape, {semantic: true, type})
403
404 callback = (marker) ->
405 { element } = marker
406 element.focus()
407 element.select?()
408
409 vim.enterMode('hints', filter, callback)
410
411 # Search for the prev/next patterns in the following attributes of the element.
412 # `rel` should be kept as the first attribute, since the standard way of marking
413 # up prev/next links (`rel="prev"` and `rel="next"`) should be favored. Even
414 # though some of these attributes only allow a fixed set of keywords, we
415 # pattern-match them anyways since lots of sites don’t follow the spec and use
416 # the attributes arbitrarily.
417 attrs = ['rel', 'role', 'data-tooltip', 'aria-label']
418 helper_follow_pattern = (type, vim) ->
419 { document } = vim.window
420
421 # If there’s a `<link rel=prev/next>` element we use that.
422 for link in document.head.getElementsByTagName('link')
423 # Also support `rel=previous`, just like Google.
424 if type == link.rel.toLowerCase().replace(/^previous$/, 'prev')
425 vim.rootWindow.gBrowser.loadURI(link.href)
426 return
427
428 # Otherwise we look for a link or button on the page that seems to go to the
429 # previous or next page.
430 candidates = document.querySelectorAll('a, button')
431 patterns = utils.splitListString(getPref("#{ type }_patterns"))
432 if matchingLink = utils.getBestPatternMatch(patterns, attrs, candidates)
433 utils.simulateClick(matchingLink)
434
435 # Follow previous page.
436 command_follow_prev = helper_follow_pattern.bind(undefined, 'prev')
437
438 # Follow next page.
439 command_follow_next = helper_follow_pattern.bind(undefined, 'next')
440
441 # Go up one level in the URL hierarchy.
442 command_go_up_path = (vim, event, count) ->
443 { pathname } = vim.window.location
444 vim.window.location.pathname = pathname.replace(
445 /// (?: /[^/]+ ){1,#{ count }} /?$ ///, ''
446 )
447
448 # Go up to root of the URL hierarchy.
449 command_go_to_root = (vim) ->
450 vim.window.location.href = vim.window.location.origin
451
452 helper_go_history = (num, vim, event, count) ->
453 { index } = vim.rootWindow.getWebNavigation().sessionHistory
454 { history } = vim.window
455 num *= count
456 num = Math.max(num, -index)
457 num = Math.min(num, history.length - 1 - index)
458 return if num == 0
459 history.go(num)
460
461 # Go back in history.
462 command_back = helper_go_history.bind(undefined, -1)
463
464 # Go forward in history.
465 command_forward = helper_go_history.bind(undefined, +1)
466
467 findStorage = {lastSearchString: ''}
468
469 helper_find = (highlight, vim) ->
470 findBar = vim.rootWindow.gBrowser.getFindBar()
471
472 findBar.onFindCommand()
473 findBar._findField.focus()
474 findBar._findField.select()
475
476 return unless highlightButton = findBar.getElement('highlight')
477 if highlightButton.checked != highlight
478 highlightButton.click()
479
480 # Open the find bar, making sure that hightlighting is off.
481 command_find = helper_find.bind(undefined, false)
482
483 # Open the find bar, making sure that hightlighting is on.
484 command_find_hl = helper_find.bind(undefined, true)
485
486 helper_find_again = (direction, vim) ->
487 findBar = vim.rootWindow.gBrowser.getFindBar()
488 if findStorage.lastSearchString.length > 0
489 findBar._findField.value = findStorage.lastSearchString
490 findBar.onFindAgainCommand(direction)
491
492 # Search for the last pattern.
493 command_find_next = helper_find_again.bind(undefined, false)
494
495 # Search for the last pattern backwards.
496 command_find_prev = helper_find_again.bind(undefined, true)
497
498 # Enter insert mode.
499 command_insert_mode = (vim) ->
500 vim.enterMode('insert')
501
502 # Quote next keypress (pass it through to the page).
503 command_quote = (vim, event, count) ->
504 vim.enterMode('insert', count)
505
506 # Display the Help Dialog.
507 command_help = (vim) ->
508 help.injectHelp(vim.window.document, require('./modes'))
509
510 # Open and select the Developer Toolbar.
511 command_dev = (vim) ->
512 vim.rootWindow.DeveloperToolbar.show(true) # focus
513
514 command_Esc = (vim, event) ->
515 utils.blurActiveElement(vim.window)
516
517 # Blur active XUL control.
518 callback = -> event.originalTarget?.ownerDocument?.activeElement?.blur()
519 vim.window.setTimeout(callback, 0)
520
521 help.removeHelp(vim.window.document)
522
523 vim.rootWindow.DeveloperToolbar.hide()
524
525 vim.rootWindow.gBrowser.getFindBar().close()
526
527 vim.rootWindow.TabView.hide()
528
529
530 class Command
531 constructor: (@group, @name, @func, keys) ->
532 @prefName = "commands.#{ @name }.keys"
533 @keyValues =
534 if isPrefSet(@prefName)
535 try JSON.parse(getPref(@prefName))
536 catch then []
537 else
538 keys
539 for key, index in @keyValues when typeof key == 'string'
540 @keyValues[index] = legacy.convertKey(key)
541
542 keys: (value) ->
543 if value == undefined
544 return @keyValues
545 else
546 @keyValues = value
547 setPref(@prefName, JSON.stringify(value))
548
549 help: -> _("help_command_#{ @name }")
550
551 match: (str, numbers = null) ->
552 for key in @keys()
553 key = utils.normalizedKey(key)
554 if key.startsWith(str)
555 # When letter 0 follows after a number, it is considered as number 0
556 # instead of a valid command.
557 continue if key == '0' and numbers
558
559 count = parseInt(numbers[numbers.length - 1], 10) if numbers
560 count = if count > 1 then count else 1
561
562 return {match: true, exact: (key == str), command: this, count}
563
564
565 # coffeelint: disable=max_line_length
566 commands = [
567 new Command('urls', 'focus', command_focus, [['o']])
568 new Command('urls', 'focus_search', command_focus_search, [['O']])
569 new Command('urls', 'paste', command_paste, [['p']])
570 new Command('urls', 'paste_tab', command_paste_tab, [['P']])
571 new Command('urls', 'marker_yank', command_marker_yank, [['y', 'f']])
572 new Command('urls', 'marker_focus', command_marker_focus, [['v', 'f']])
573 new Command('urls', 'yank', command_yank, [['y', 'y']])
574 new Command('urls', 'reload', command_reload, [['r']])
575 new Command('urls', 'reload_force', command_reload_force, [['R']])
576 new Command('urls', 'reload_all', command_reload_all, [['a', 'r']])
577 new Command('urls', 'reload_all_force', command_reload_all_force, [['a', 'R']])
578 new Command('urls', 'stop', command_stop, [['s']])
579 new Command('urls', 'stop_all', command_stop_all, [['a', 's']])
580
581 new Command('nav', 'scroll_to_top', command_scroll_to_top , [['g', 'g']])
582 new Command('nav', 'scroll_to_bottom', command_scroll_to_bottom, [['G']])
583 new Command('nav', 'scroll_down', command_scroll_down, [['j']])
584 new Command('nav', 'scroll_up', command_scroll_up, [['k']])
585 new Command('nav', 'scroll_left', command_scroll_left, [['h']])
586 new Command('nav', 'scroll_right', command_scroll_right , [['l']])
587 new Command('nav', 'scroll_half_page_down', command_scroll_half_page_down, [['d']])
588 new Command('nav', 'scroll_half_page_up', command_scroll_half_page_up, [['u']])
589 new Command('nav', 'scroll_page_down', command_scroll_page_down, [['<space>']])
590 new Command('nav', 'scroll_page_up', command_scroll_page_up, [['<s-space>']])
591
592 new Command('tabs', 'open_tab', command_open_tab, [['t']])
593 new Command('tabs', 'tab_prev', command_tab_prev, [['J'], ['g', 'T']])
594 new Command('tabs', 'tab_next', command_tab_next, [['K'], ['g', 't']])
595 new Command('tabs', 'tab_move_left', command_tab_move_left, [['g', 'J']])
596 new Command('tabs', 'tab_move_right', command_tab_move_right, [['g', 'K']])
597 new Command('tabs', 'home', command_home, [['g', 'h']])
598 new Command('tabs', 'tab_first', command_tab_first, [['g', 'H'], ['g', '0']])
599 new Command('tabs', 'tab_first_non_pinned', command_tab_first_non_pinned, [['g', '^']])
600 new Command('tabs', 'tab_last', command_tab_last, [['g', 'L'], ['g', '$']])
601 new Command('tabs', 'toggle_pin_tab', command_toggle_pin_tab, [['g', 'p']])
602 new Command('tabs', 'duplicate_tab', command_duplicate_tab, [['y', 't']])
603 new Command('tabs', 'close_tabs_to_end', command_close_tabs_to_end, [['g', 'x', '$']])
604 new Command('tabs', 'close_other_tabs', command_close_other_tabs, [['g', 'x', 'a']])
605 new Command('tabs', 'close_tab', command_close_tab, [['x']])
606 new Command('tabs', 'restore_tab', command_restore_tab, [['X']])
607
608 new Command('browse', 'follow', command_follow, [['f']])
609 new Command('browse', 'follow_in_tab', command_follow_in_tab, [['F']])
610 new Command('browse', 'follow_in_focused_tab', command_follow_in_focused_tab, [['g', 'f']])
611 new Command('browse', 'follow_multiple', command_follow_multiple, [['a', 'f']])
612 new Command('browse', 'follow_previous', command_follow_prev, [['[']])
613 new Command('browse', 'follow_next', command_follow_next, [[']']])
614 new Command('browse', 'go_up_path', command_go_up_path, [['g', 'u']])
615 new Command('browse', 'go_to_root', command_go_to_root, [['g', 'U']])
616 new Command('browse', 'back', command_back, [['H']])
617 new Command('browse', 'forward', command_forward, [['L']])
618
619 new Command('misc', 'find', command_find, [['/']])
620 new Command('misc', 'find_hl', command_find_hl, [['a', '/']])
621 new Command('misc', 'find_next', command_find_next, [['n']])
622 new Command('misc', 'find_prev', command_find_prev, [['N']])
623 new Command('misc', 'insert_mode', command_insert_mode, [['i']])
624 new Command('misc', 'quote', command_quote, [['I']])
625 new Command('misc', 'help', command_help, [['?']])
626 new Command('misc', 'dev', command_dev, [[':']])
627
628 escapeCommand =
629 new Command('misc', 'Esc', command_Esc, [['<escape>']])
630 ]
631 # coffeelint: enable=max_line_length
632
633 searchForMatchingCommand = (keys) ->
634 for index in [0...keys.length] by 1
635 str = keys[index..].join('')
636 numbers = keys[0..index].join('').match(/[1-9]\d*/g)
637 for command in commands
638 return match if match = command.match(str, numbers)
639 return {match: false}
640
641 exports.commands = commands
642 exports.searchForMatchingCommand = searchForMatchingCommand
643 exports.escapeCommand = escapeCommand
644 exports.Command = Command
645 exports.findStorage = findStorage
Imprint / Impressum