]> git.gir.st - VimFx.git/blob - extension/lib/commands.coffee
Fix #440: Hint markers on feedly.com
[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') or
292 # Feedly special-case.
293 element.hasAttribute('data-app-action') or
294 element.hasAttribute('data-uri') or
295 element.hasAttribute('data-page-action')
296 type = 'clickable'
297 semantic = false
298 # Putting markers on `<label>` elements is generally redundant, because
299 # its `<input>` gets one. However, some sites hide the actual `<input>`
300 # but keeps the `<label>` to click, either for styling purposes or to keep
301 # the `<input>` hidden until it is used. In those cases we should add a
302 # marker for the `<label>`.
303 when element.nodeName == 'LABEL'
304 if element.htmlFor
305 input = document.getElementById(element.htmlFor)
306 if input and not getElementShape(input)
307 type = 'clickable'
308 # Elements that have “button” somewhere in the class might be clickable,
309 # unless they contain a real link or button in which case they likely are
310 # “button-wrapper”s. (`<SVG element>.className` is not a string!)
311 when not isXUL and typeof element.className == 'string' and
312 element.className.toLowerCase().contains('button')
313 unless element.querySelector('a, button')
314 type = 'clickable'
315 semantic = false
316 # When viewing an image it should get a marker to toggle zoom.
317 when document.body?.childElementCount == 1 and
318 element.nodeName == 'IMG' and
319 (element.classList.contains('overflowing') or
320 element.classList.contains('shrinkToFit'))
321 type = 'clickable'
322 return unless type
323 return unless shape = getElementShape(element)
324 return combine(hrefs, new Marker(element, shape, {semantic, type}))
325
326 callback = (marker) ->
327 { element } = marker
328 element.focus()
329 last = (count == 1)
330 if not last and marker.type == 'link'
331 utils.openTab(vim.rootWindow, element.href, {
332 inBackground: true
333 relatedToCurrent: true
334 })
335 else
336 if element.target == '_blank'
337 targetReset = element.target
338 element.target = ''
339 utils.simulateClick(element)
340 element.target = targetReset if targetReset
341 count--
342 return (not last and marker.type != 'text')
343
344 vim.enterMode('hints', filter, callback)
345
346 # Like command_follow but multiple times.
347 command_follow_multiple = (vim, event) ->
348 command_follow(vim, event, Infinity)
349
350 # Follow links in a new background tab with hint markers.
351 command_follow_in_tab = (vim, event, count, inBackground = true) ->
352 hrefs = {}
353 filter = (element, getElementShape) ->
354 return unless isProperLink(element)
355 return unless shape = getElementShape(element)
356 return combine(hrefs, new Marker(element, shape, {semantic: true}))
357
358 callback = (marker) ->
359 last = (count == 1)
360 utils.openTab(vim.rootWindow, marker.element.href, {
361 inBackground: if last then inBackground else true
362 relatedToCurrent: true
363 })
364 count--
365 return not last
366
367 vim.enterMode('hints', filter, callback)
368
369 # Follow links in a new foreground tab with hint markers.
370 command_follow_in_focused_tab = (vim, event, count) ->
371 command_follow_in_tab(vim, event, count, false)
372
373 # Copy the URL or text of a markable element to the system clipboard.
374 command_marker_yank = (vim) ->
375 hrefs = {}
376 filter = (element, getElementShape) ->
377 type = switch
378 when isProperLink(element) then 'link'
379 when isTextInputElement(element) then 'textInput'
380 when isContentEditable(element) then 'contenteditable'
381 return unless type
382 return unless shape = getElementShape(element)
383 return combine(hrefs, new Marker(element, shape, {semantic: true, type}))
384
385 callback = (marker) ->
386 { element } = marker
387 text = switch marker.type
388 when 'link' then element.href
389 when 'textInput' then element.value
390 when 'contenteditable' then element.textContent
391 utils.writeToClipboard(text)
392
393 vim.enterMode('hints', filter, callback)
394
395 # Focus element with hint markers.
396 command_marker_focus = (vim) ->
397 filter = (element, getElementShape) ->
398 type = switch
399 when element.tabIndex > -1
400 'focusable'
401 when element != vim.state.largestScrollableElement and
402 vim.state.scrollableElements.has(element)
403 'scrollable'
404 return unless type
405 return unless shape = getElementShape(element)
406 return new Marker(element, shape, {semantic: true, type})
407
408 callback = (marker) ->
409 { element } = marker
410 element.focus()
411 element.select?()
412
413 vim.enterMode('hints', filter, callback)
414
415 # Search for the prev/next patterns in the following attributes of the element.
416 # `rel` should be kept as the first attribute, since the standard way of marking
417 # up prev/next links (`rel="prev"` and `rel="next"`) should be favored. Even
418 # though some of these attributes only allow a fixed set of keywords, we
419 # pattern-match them anyways since lots of sites don’t follow the spec and use
420 # the attributes arbitrarily.
421 attrs = ['rel', 'role', 'data-tooltip', 'aria-label']
422 helper_follow_pattern = (type, vim) ->
423 { document } = vim.window
424
425 # If there’s a `<link rel=prev/next>` element we use that.
426 for link in document.head.getElementsByTagName('link')
427 # Also support `rel=previous`, just like Google.
428 if type == link.rel.toLowerCase().replace(/^previous$/, 'prev')
429 vim.rootWindow.gBrowser.loadURI(link.href)
430 return
431
432 # Otherwise we look for a link or button on the page that seems to go to the
433 # previous or next page.
434 candidates = document.querySelectorAll('a, button')
435 patterns = utils.splitListString(getPref("#{ type }_patterns"))
436 if matchingLink = utils.getBestPatternMatch(patterns, attrs, candidates)
437 utils.simulateClick(matchingLink)
438
439 # Follow previous page.
440 command_follow_prev = helper_follow_pattern.bind(undefined, 'prev')
441
442 # Follow next page.
443 command_follow_next = helper_follow_pattern.bind(undefined, 'next')
444
445 # Go up one level in the URL hierarchy.
446 command_go_up_path = (vim, event, count) ->
447 { pathname } = vim.window.location
448 vim.window.location.pathname = pathname.replace(
449 /// (?: /[^/]+ ){1,#{ count }} /?$ ///, ''
450 )
451
452 # Go up to root of the URL hierarchy.
453 command_go_to_root = (vim) ->
454 vim.window.location.href = vim.window.location.origin
455
456 helper_go_history = (num, vim, event, count) ->
457 { index } = vim.rootWindow.getWebNavigation().sessionHistory
458 { history } = vim.window
459 num *= count
460 num = Math.max(num, -index)
461 num = Math.min(num, history.length - 1 - index)
462 return if num == 0
463 history.go(num)
464
465 # Go back in history.
466 command_back = helper_go_history.bind(undefined, -1)
467
468 # Go forward in history.
469 command_forward = helper_go_history.bind(undefined, +1)
470
471 findStorage = {lastSearchString: ''}
472
473 helper_find = (highlight, vim) ->
474 findBar = vim.rootWindow.gBrowser.getFindBar()
475
476 findBar.onFindCommand()
477 findBar._findField.focus()
478 findBar._findField.select()
479
480 return unless highlightButton = findBar.getElement('highlight')
481 if highlightButton.checked != highlight
482 highlightButton.click()
483
484 # Open the find bar, making sure that hightlighting is off.
485 command_find = helper_find.bind(undefined, false)
486
487 # Open the find bar, making sure that hightlighting is on.
488 command_find_hl = helper_find.bind(undefined, true)
489
490 helper_find_again = (direction, vim) ->
491 findBar = vim.rootWindow.gBrowser.getFindBar()
492 if findStorage.lastSearchString.length > 0
493 findBar._findField.value = findStorage.lastSearchString
494 findBar.onFindAgainCommand(direction)
495
496 # Search for the last pattern.
497 command_find_next = helper_find_again.bind(undefined, false)
498
499 # Search for the last pattern backwards.
500 command_find_prev = helper_find_again.bind(undefined, true)
501
502 # Enter insert mode.
503 command_insert_mode = (vim) ->
504 vim.enterMode('insert')
505
506 # Quote next keypress (pass it through to the page).
507 command_quote = (vim, event, count) ->
508 vim.enterMode('insert', count)
509
510 # Display the Help Dialog.
511 command_help = (vim) ->
512 help.injectHelp(vim.window.document, require('./modes'))
513
514 # Open and select the Developer Toolbar.
515 command_dev = (vim) ->
516 vim.rootWindow.DeveloperToolbar.show(true) # focus
517
518 command_Esc = (vim, event) ->
519 utils.blurActiveElement(vim.window)
520
521 # Blur active XUL control.
522 callback = -> event.originalTarget?.ownerDocument?.activeElement?.blur()
523 vim.window.setTimeout(callback, 0)
524
525 help.removeHelp(vim.window.document)
526
527 vim.rootWindow.DeveloperToolbar.hide()
528
529 vim.rootWindow.gBrowser.getFindBar().close()
530
531 vim.rootWindow.TabView.hide()
532
533 { document } = vim.window
534 if document.exitFullscreen
535 document.exitFullscreen()
536 else
537 document.mozCancelFullScreen()
538
539
540 class Command
541 constructor: (@group, @name, @func, keys) ->
542 @prefName = "commands.#{ @name }.keys"
543 @keyValues =
544 if isPrefSet(@prefName)
545 try JSON.parse(getPref(@prefName))
546 catch then []
547 else
548 keys
549 for key, index in @keyValues when typeof key == 'string'
550 @keyValues[index] = legacy.convertKey(key)
551
552 keys: (value) ->
553 if value == undefined
554 return @keyValues
555 else
556 @keyValues = value
557 setPref(@prefName, JSON.stringify(value))
558
559 help: -> _("help_command_#{ @name }")
560
561 match: (str, numbers = null) ->
562 for key in @keys()
563 key = utils.normalizedKey(key)
564 if key.startsWith(str)
565 # When letter 0 follows after a number, it is considered as number 0
566 # instead of a valid command.
567 continue if key == '0' and numbers
568
569 count = parseInt(numbers[numbers.length - 1], 10) if numbers
570 count = if count > 1 then count else 1
571
572 return {match: true, exact: (key == str), command: this, count}
573
574
575 # coffeelint: disable=max_line_length
576 commands = [
577 new Command('urls', 'focus', command_focus, [['o']])
578 new Command('urls', 'focus_search', command_focus_search, [['O']])
579 new Command('urls', 'paste', command_paste, [['p']])
580 new Command('urls', 'paste_tab', command_paste_tab, [['P']])
581 new Command('urls', 'marker_yank', command_marker_yank, [['y', 'f']])
582 new Command('urls', 'marker_focus', command_marker_focus, [['v', 'f']])
583 new Command('urls', 'yank', command_yank, [['y', 'y']])
584 new Command('urls', 'reload', command_reload, [['r']])
585 new Command('urls', 'reload_force', command_reload_force, [['R']])
586 new Command('urls', 'reload_all', command_reload_all, [['a', 'r']])
587 new Command('urls', 'reload_all_force', command_reload_all_force, [['a', 'R']])
588 new Command('urls', 'stop', command_stop, [['s']])
589 new Command('urls', 'stop_all', command_stop_all, [['a', 's']])
590
591 new Command('nav', 'scroll_to_top', command_scroll_to_top , [['g', 'g']])
592 new Command('nav', 'scroll_to_bottom', command_scroll_to_bottom, [['G']])
593 new Command('nav', 'scroll_down', command_scroll_down, [['j']])
594 new Command('nav', 'scroll_up', command_scroll_up, [['k']])
595 new Command('nav', 'scroll_left', command_scroll_left, [['h']])
596 new Command('nav', 'scroll_right', command_scroll_right , [['l']])
597 new Command('nav', 'scroll_half_page_down', command_scroll_half_page_down, [['d']])
598 new Command('nav', 'scroll_half_page_up', command_scroll_half_page_up, [['u']])
599 new Command('nav', 'scroll_page_down', command_scroll_page_down, [['<space>']])
600 new Command('nav', 'scroll_page_up', command_scroll_page_up, [['<s-space>']])
601
602 new Command('tabs', 'open_tab', command_open_tab, [['t']])
603 new Command('tabs', 'tab_prev', command_tab_prev, [['J'], ['g', 'T']])
604 new Command('tabs', 'tab_next', command_tab_next, [['K'], ['g', 't']])
605 new Command('tabs', 'tab_move_left', command_tab_move_left, [['g', 'J']])
606 new Command('tabs', 'tab_move_right', command_tab_move_right, [['g', 'K']])
607 new Command('tabs', 'home', command_home, [['g', 'h']])
608 new Command('tabs', 'tab_first', command_tab_first, [['g', 'H'], ['g', '0']])
609 new Command('tabs', 'tab_first_non_pinned', command_tab_first_non_pinned, [['g', '^']])
610 new Command('tabs', 'tab_last', command_tab_last, [['g', 'L'], ['g', '$']])
611 new Command('tabs', 'toggle_pin_tab', command_toggle_pin_tab, [['g', 'p']])
612 new Command('tabs', 'duplicate_tab', command_duplicate_tab, [['y', 't']])
613 new Command('tabs', 'close_tabs_to_end', command_close_tabs_to_end, [['g', 'x', '$']])
614 new Command('tabs', 'close_other_tabs', command_close_other_tabs, [['g', 'x', 'a']])
615 new Command('tabs', 'close_tab', command_close_tab, [['x']])
616 new Command('tabs', 'restore_tab', command_restore_tab, [['X']])
617
618 new Command('browse', 'follow', command_follow, [['f']])
619 new Command('browse', 'follow_in_tab', command_follow_in_tab, [['F']])
620 new Command('browse', 'follow_in_focused_tab', command_follow_in_focused_tab, [['g', 'f']])
621 new Command('browse', 'follow_multiple', command_follow_multiple, [['a', 'f']])
622 new Command('browse', 'follow_previous', command_follow_prev, [['[']])
623 new Command('browse', 'follow_next', command_follow_next, [[']']])
624 new Command('browse', 'go_up_path', command_go_up_path, [['g', 'u']])
625 new Command('browse', 'go_to_root', command_go_to_root, [['g', 'U']])
626 new Command('browse', 'back', command_back, [['H']])
627 new Command('browse', 'forward', command_forward, [['L']])
628
629 new Command('misc', 'find', command_find, [['/']])
630 new Command('misc', 'find_hl', command_find_hl, [['a', '/']])
631 new Command('misc', 'find_next', command_find_next, [['n']])
632 new Command('misc', 'find_prev', command_find_prev, [['N']])
633 new Command('misc', 'insert_mode', command_insert_mode, [['i']])
634 new Command('misc', 'quote', command_quote, [['I']])
635 new Command('misc', 'help', command_help, [['?']])
636 new Command('misc', 'dev', command_dev, [[':']])
637
638 escapeCommand =
639 new Command('misc', 'Esc', command_Esc, [['<escape>']])
640 ]
641 # coffeelint: enable=max_line_length
642
643 searchForMatchingCommand = (keys) ->
644 for index in [0...keys.length] by 1
645 str = keys[index..].join('')
646 numbers = keys[0..index].join('').match(/[1-9]\d*/g)
647 for command in commands
648 return match if match = command.match(str, numbers)
649 return {match: false}
650
651 exports.commands = commands
652 exports.searchForMatchingCommand = searchForMatchingCommand
653 exports.escapeCommand = escapeCommand
654 exports.Command = Command
655 exports.findStorage = findStorage
Imprint / Impressum