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