]> git.gir.st - VimFx.git/blob - extension/lib/commands.coffee
Add the `<c-a>` Hints mode command to mark everything
[VimFx.git] / extension / lib / commands.coffee
1 ###
2 # Copyright Anton Khodakivskiy 2012, 2013, 2014.
3 # Copyright Simon Lydell 2013, 2014, 2015, 2016.
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 # This file defines all Normal mode commands. Commands that need to interact
23 # with web page content do so by running `vim._run(name)`, which invokes `name`
24 # in commands-frame.coffee.
25
26 # NOTE: Most tab related commands need to do their actual tab manipulations in
27 # the next tick (`utils.nextTick`) to work around bug 1200334.
28
29 config = require('./config')
30 help = require('./help')
31 hints = require('./hints')
32 prefs = require('./prefs')
33 translate = require('./l10n')
34 utils = require('./utils')
35
36 commands = {}
37
38
39
40 commands.focus_location_bar = ({vim}) ->
41 vim.window.focusAndSelectUrlBar()
42
43 commands.focus_search_bar = ({vim, count}) ->
44 # The `.webSearch()` method opens a search engine in a tab if the search bar
45 # has been removed. Therefore we first check if it exists.
46 if vim.window.BrowserSearch.searchBar
47 vim.window.BrowserSearch.webSearch()
48 else
49 vim.notify(translate('notification.focus_search_bar.none'))
50
51 helper_paste_and_go = (props, {vim}) ->
52 {gURLBar} = vim.window
53 gURLBar.value = vim.window.readFromClipboard()
54 gURLBar.handleCommand(new vim.window.KeyboardEvent('keydown', props))
55
56 commands.paste_and_go = helper_paste_and_go.bind(null, null)
57
58 commands.paste_and_go_in_tab = helper_paste_and_go.bind(null, {altKey: true})
59
60 commands.copy_current_url = ({vim}) ->
61 utils.writeToClipboard(vim.window.gBrowser.currentURI.spec)
62 vim.notify(translate('notification.copy_current_url.success'))
63
64 commands.go_up_path = ({vim, count}) ->
65 vim._run('go_up_path', {count})
66
67 commands.go_to_root = ({vim}) ->
68 vim._run('go_to_root')
69
70 commands.go_home = ({vim}) ->
71 vim.window.BrowserHome()
72
73 helper_go_history = (direction, {vim, count = 1}) ->
74 {window} = vim
75 {SessionStore, gBrowser} = window
76
77 if (direction == 'back' and not gBrowser.canGoBack) or
78 (direction == 'forward' and not gBrowser.canGoForward)
79 vim.notify(translate("notification.history_#{direction}.limit"))
80 return
81
82 # `SessionStore.getSessionHistory()` (used below to support counts) starts
83 # lots of asynchronous tasks internally, which is a bit unreliable, it has
84 # turned out. The primary use of the `history_back` and `history_forward`
85 # commands is to go _one_ step back or forward, though, so those cases are
86 # optimized to use more reliable ways of going back and forward. Also, some
87 # extensions override the following functions, so calling them also gives
88 # better interoperability.
89 if count == 1
90 if direction == 'back'
91 window.BrowserBack()
92 else
93 window.BrowserForward()
94 return
95
96 SessionStore.getSessionHistory(gBrowser.selectedTab, (sessionHistory) ->
97 {index} = sessionHistory
98 newIndex = index + count * (if direction == 'back' then -1 else 1)
99 newIndex = Math.max(newIndex, 0)
100 newIndex = Math.min(newIndex, sessionHistory.entries.length - 1)
101 gBrowser.gotoIndex(newIndex)
102 )
103
104 commands.history_back = helper_go_history.bind(null, 'back')
105
106 commands.history_forward = helper_go_history.bind(null, 'forward')
107
108 commands.history_list = ({vim}) ->
109 menu = vim.window.document.getElementById('backForwardMenu')
110 utils.openPopup(menu)
111 if menu.childElementCount == 0
112 vim.notify(translate('notification.history_list.none'))
113
114 commands.reload = ({vim}) ->
115 vim.window.BrowserReload()
116
117 commands.reload_force = ({vim}) ->
118 vim.window.BrowserReloadSkipCache()
119
120 commands.reload_all = ({vim}) ->
121 vim.window.gBrowser.reloadAllTabs()
122
123 commands.reload_all_force = ({vim}) ->
124 for tab in vim.window.gBrowser.visibleTabs
125 gBrowser = tab.linkedBrowser
126 consts = gBrowser.webNavigation
127 flags = consts.LOAD_FLAGS_BYPASS_PROXY | consts.LOAD_FLAGS_BYPASS_CACHE
128 gBrowser.reload(flags)
129 return
130
131 commands.stop = ({vim}) ->
132 vim.window.BrowserStop()
133
134 commands.stop_all = ({vim}) ->
135 for tab in vim.window.gBrowser.visibleTabs
136 tab.linkedBrowser.stop()
137 return
138
139
140
141 helper_scroll = (vim, uiEvent, args...) ->
142 [
143 method, type, directions, amounts
144 properties = null, adjustment = 0, name = 'scroll'
145 ] = args
146 options = {
147 method, type, directions, amounts, properties, adjustment
148 smooth: (
149 prefs.root.get('general.smoothScroll') and
150 prefs.root.get("general.smoothScroll.#{type}")
151 )
152 }
153 reset = prefs.root.tmp(
154 'layout.css.scroll-behavior.spring-constant',
155 vim.options["smoothScroll.#{type}.spring-constant"]
156 )
157
158 helpScroll = help.getHelp(vim.window)?.querySelector('.wrapper')
159 if uiEvent or helpScroll
160 activeElement = helpScroll or utils.getActiveElement(vim.window)
161 if vim._state.scrollableElements.has(activeElement) or helpScroll
162 utils.scroll(activeElement, options)
163 reset()
164 return
165
166 vim._run(name, options, reset)
167
168
169 helper_scrollByLinesX = (amount, {vim, uiEvent, count = 1}) ->
170 distance = prefs.root.get('toolkit.scrollbox.horizontalScrollDistance')
171 helper_scroll(
172 vim, uiEvent, 'scrollBy', 'lines', ['left'], [amount * distance * count * 5]
173 )
174
175 helper_scrollByLinesY = (amount, {vim, uiEvent, count = 1}) ->
176 distance = prefs.root.get('toolkit.scrollbox.verticalScrollDistance')
177 helper_scroll(
178 vim, uiEvent, 'scrollBy', 'lines', ['top'], [amount * distance * count * 20]
179 )
180
181 helper_scrollByPagesY = (amount, type, {vim, uiEvent, count = 1}) ->
182 adjustment = vim.options["scroll.#{type}_page_adjustment"]
183 helper_scroll(
184 vim, uiEvent, 'scrollBy', 'pages', ['top'], [amount * count],
185 ['clientHeight'], adjustment
186 )
187
188 helper_scrollToX = (amount, {vim, uiEvent}) ->
189 helper_mark_last_scroll_position(vim)
190 helper_scroll(
191 vim, uiEvent, 'scrollTo', 'other', ['left'], [amount], ['scrollLeftMax']
192 )
193
194 helper_scrollToY = (amount, {vim, uiEvent}) ->
195 helper_mark_last_scroll_position(vim)
196 helper_scroll(
197 vim, uiEvent, 'scrollTo', 'other', ['top'], [amount], ['scrollTopMax']
198 )
199
200 commands.scroll_left = helper_scrollByLinesX.bind(null, -1)
201 commands.scroll_right = helper_scrollByLinesX.bind(null, +1)
202 commands.scroll_down = helper_scrollByLinesY.bind(null, +1)
203 commands.scroll_up = helper_scrollByLinesY.bind(null, -1)
204 commands.scroll_page_down = helper_scrollByPagesY.bind(null, +1, 'full')
205 commands.scroll_page_up = helper_scrollByPagesY.bind(null, -1, 'full')
206 commands.scroll_half_page_down = helper_scrollByPagesY.bind(null, +0.5, 'half')
207 commands.scroll_half_page_up = helper_scrollByPagesY.bind(null, -0.5, 'half')
208 commands.scroll_to_top = helper_scrollToY.bind(null, 0)
209 commands.scroll_to_bottom = helper_scrollToY.bind(null, Infinity)
210 commands.scroll_to_left = helper_scrollToX.bind(null, 0)
211 commands.scroll_to_right = helper_scrollToX.bind(null, Infinity)
212
213 helper_mark_last_scroll_position = (vim) ->
214 keyStr = vim.options['scroll.last_position_mark']
215 vim._run('mark_scroll_position', {keyStr, notify: false})
216
217 commands.mark_scroll_position = ({vim}) ->
218 vim.enterMode('marks', (keyStr) -> vim._run('mark_scroll_position', {keyStr}))
219 vim.notify(translate('notification.mark_scroll_position.enter'))
220
221 commands.scroll_to_mark = ({vim}) ->
222 vim.enterMode('marks', (keyStr) ->
223 unless keyStr == vim.options['scroll.last_position_mark']
224 helper_mark_last_scroll_position(vim)
225 helper_scroll(
226 vim, null, 'scrollTo', 'other', ['top', 'left'], keyStr,
227 ['scrollTopMax', 'scrollLeftMax'], 0, 'scroll_to_mark'
228 )
229 )
230 vim.notify(translate('notification.scroll_to_mark.enter'))
231
232
233
234 commands.tab_new = ({vim}) ->
235 utils.nextTick(vim.window, ->
236 vim.window.BrowserOpenTab()
237 )
238
239 commands.tab_new_after_current = ({vim}) ->
240 {window} = vim
241 newTabPosition = window.gBrowser.selectedTab._tPos + 1
242 utils.nextTick(window, ->
243 utils.listenOnce(window, 'TabOpen', (event) ->
244 newTab = event.originalTarget
245 window.gBrowser.moveTabTo(newTab, newTabPosition)
246 )
247 window.BrowserOpenTab()
248 )
249
250 commands.tab_duplicate = ({vim}) ->
251 {gBrowser} = vim.window
252 utils.nextTick(vim.window, ->
253 gBrowser.duplicateTab(gBrowser.selectedTab)
254 )
255
256 absoluteTabIndex = (relativeIndex, gBrowser, {pinnedSeparate}) ->
257 tabs = gBrowser.visibleTabs
258 {selectedTab} = gBrowser
259
260 currentIndex = tabs.indexOf(selectedTab)
261 absoluteIndex = currentIndex + relativeIndex
262 numTabsTotal = tabs.length
263 numPinnedTabs = gBrowser._numPinnedTabs
264
265 [numTabs, min] = switch
266 when not pinnedSeparate
267 [numTabsTotal, 0]
268 when selectedTab.pinned
269 [numPinnedTabs, 0]
270 else
271 [numTabsTotal - numPinnedTabs, numPinnedTabs]
272
273 # Wrap _once_ if at one of the ends of the tab bar and cannot move in the
274 # current direction.
275 if (relativeIndex < 0 and currentIndex == min) or
276 (relativeIndex > 0 and currentIndex == min + numTabs - 1)
277 if absoluteIndex < min
278 absoluteIndex += numTabs
279 else if absoluteIndex >= min + numTabs
280 absoluteIndex -= numTabs
281
282 absoluteIndex = Math.max(min, absoluteIndex)
283 absoluteIndex = Math.min(absoluteIndex, min + numTabs - 1)
284
285 return absoluteIndex
286
287 helper_switch_tab = (direction, {vim, count = 1}) ->
288 {gBrowser} = vim.window
289 index = absoluteTabIndex(direction * count, gBrowser, {pinnedSeparate: false})
290 utils.nextTick(vim.window, ->
291 gBrowser.selectTabAtIndex(index)
292 )
293
294 commands.tab_select_previous = helper_switch_tab.bind(null, -1)
295
296 commands.tab_select_next = helper_switch_tab.bind(null, +1)
297
298 helper_is_visited = (tab) ->
299 return tab.getAttribute('VimFx-visited') or not tab.getAttribute('unread')
300
301 commands.tab_select_most_recent = ({vim, count = 1}) ->
302 {gBrowser} = vim.window
303 tabsSorted =
304 Array.filter(
305 gBrowser.tabs,
306 (tab) -> not tab.closing and helper_is_visited(tab)
307 ).sort((a, b) -> b.lastAccessed - a.lastAccessed)[1..] # Remove current tab.
308 tab = tabsSorted[Math.min(count - 1, tabsSorted.length - 1)]
309 if tab
310 gBrowser.selectedTab = tab
311 else
312 vim.notify(translate('notification.tab_select_most_recent.none'))
313
314 commands.tab_select_oldest_unvisited = ({vim, count = 1}) ->
315 {gBrowser} = vim.window
316 tabsSorted =
317 Array.filter(
318 gBrowser.tabs,
319 (tab) -> not tab.closing and not helper_is_visited(tab)
320 ).sort((a, b) -> a.lastAccessed - b.lastAccessed)
321 tab = tabsSorted[Math.min(count - 1, tabsSorted.length - 1)]
322 if tab
323 gBrowser.selectedTab = tab
324 else
325 vim.notify(translate('notification.tab_select_oldest_unvisited.none'))
326
327 helper_move_tab = (direction, {vim, count = 1}) ->
328 {gBrowser} = vim.window
329 index = absoluteTabIndex(direction * count, gBrowser, {pinnedSeparate: true})
330 utils.nextTick(vim.window, ->
331 gBrowser.moveTabTo(gBrowser.selectedTab, index)
332 )
333
334 commands.tab_move_backward = helper_move_tab.bind(null, -1)
335
336 commands.tab_move_forward = helper_move_tab.bind(null, +1)
337
338 commands.tab_move_to_window = ({vim}) ->
339 {gBrowser} = vim.window
340 gBrowser.replaceTabWithWindow(gBrowser.selectedTab)
341
342 commands.tab_select_first = ({vim, count = 1}) ->
343 utils.nextTick(vim.window, ->
344 vim.window.gBrowser.selectTabAtIndex(count - 1)
345 )
346
347 commands.tab_select_first_non_pinned = ({vim, count = 1}) ->
348 firstNonPinned = vim.window.gBrowser._numPinnedTabs
349 utils.nextTick(vim.window, ->
350 vim.window.gBrowser.selectTabAtIndex(firstNonPinned + count - 1)
351 )
352
353 commands.tab_select_last = ({vim, count = 1}) ->
354 utils.nextTick(vim.window, ->
355 vim.window.gBrowser.selectTabAtIndex(-count)
356 )
357
358 commands.tab_toggle_pinned = ({vim}) ->
359 currentTab = vim.window.gBrowser.selectedTab
360 if currentTab.pinned
361 vim.window.gBrowser.unpinTab(currentTab)
362 else
363 vim.window.gBrowser.pinTab(currentTab)
364
365 commands.tab_close = ({vim, count = 1}) ->
366 {gBrowser} = vim.window
367 return if gBrowser.selectedTab.pinned
368 currentIndex = gBrowser.visibleTabs.indexOf(gBrowser.selectedTab)
369 utils.nextTick(vim.window, ->
370 for tab in gBrowser.visibleTabs[currentIndex...(currentIndex + count)]
371 gBrowser.removeTab(tab)
372 return
373 )
374
375 commands.tab_restore = ({vim, count = 1}) ->
376 utils.nextTick(vim.window, ->
377 for index in [0...count] by 1
378 restoredTab = vim.window.undoCloseTab()
379 if not restoredTab and index == 0
380 vim.notify(translate('notification.tab_restore.none'))
381 break
382 return
383 )
384
385 commands.tab_restore_list = ({vim}) ->
386 {window} = vim
387 fragment = window.RecentlyClosedTabsAndWindowsMenuUtils.getTabsFragment(
388 window, 'menuitem'
389 )
390 if fragment.childElementCount == 0
391 vim.notify(translate('notification.tab_restore.none'))
392 else
393 utils.openPopup(utils.injectTemporaryPopup(window.document, fragment))
394
395 commands.tab_close_to_end = ({vim}) ->
396 {gBrowser} = vim.window
397 gBrowser.removeTabsToTheEndFrom(gBrowser.selectedTab)
398
399 commands.tab_close_other = ({vim}) ->
400 {gBrowser} = vim.window
401 gBrowser.removeAllTabsBut(gBrowser.selectedTab)
402
403
404
405 helper_follow = (name, vim, callback, count = null) ->
406 vim.markPageInteraction()
407 help.removeHelp(vim.window)
408
409 # Enter hints mode immediately, with an empty set of markers. The user might
410 # press keys before the `vim._run` callback is invoked. Those key presses
411 # should be handled in hints mode, not normal mode.
412 initialMarkers = []
413 storage = vim.enterMode(
414 'hints', initialMarkers, callback, count, vim.options.hints_sleep
415 )
416
417 setMarkers = ({wrappers, viewport}) ->
418 if wrappers.length > 0
419 {markers, markerMap} = hints.injectHints(
420 vim.window, wrappers, viewport, vim.options
421 )
422 storage.markers = markers
423 storage.markerMap = markerMap
424 else
425 vim.notify(translate('notification.follow.none'))
426 vim.enterMode('normal')
427
428 vim._run(name, {}, (result) ->
429 # The user might have exited hints mode (and perhaps even entered it again)
430 # before this callback is invoked. If so, `storage.markers` has been
431 # cleared, or set to a new value. Only proceed if it is unchanged.
432 return unless storage.markers == initialMarkers
433 setMarkers(result)
434 storage.markEverything = ->
435 lastMarkers = storage.markers
436 vim._run(name, {markEverything: true}, (newResult) ->
437 return unless storage.markers == lastMarkers
438 setMarkers(newResult)
439 )
440 )
441
442 helper_follow_clickable = (options, {vim, count = 1}) ->
443 callback = (marker, timesLeft, keyStr) ->
444 {inTab, inBackground} = options
445 {type, elementIndex} = marker.wrapper
446 isLast = (timesLeft == 1)
447 isLink = (type == 'link')
448
449 switch
450 when keyStr.startsWith(vim.options.hints_toggle_in_tab)
451 inTab = not inTab
452 when keyStr.startsWith(vim.options.hints_toggle_in_background)
453 inTab = true
454 inBackground = not inBackground
455 else
456 unless isLast
457 inTab = true
458 inBackground = true
459
460 inTab = false unless isLink
461
462 if type == 'text' or (isLink and not (inTab and inBackground))
463 isLast = true
464
465 vim._focusMarkerElement(elementIndex)
466
467 if inTab
468 utils.nextTick(vim.window, ->
469 utils.openTab(vim.window, marker.wrapper.href, {
470 inBackground
471 relatedToCurrent: true
472 })
473 )
474 else
475 vim._run('click_marker_element', {
476 elementIndex, type
477 preventTargetBlank: vim.options.prevent_target_blank
478 })
479
480 return not isLast
481
482 name = if options.inTab then 'follow_in_tab' else 'follow'
483 helper_follow(name, vim, callback, count)
484
485 commands.follow =
486 helper_follow_clickable.bind(null, {inTab: false, inBackground: true})
487
488 commands.follow_in_tab =
489 helper_follow_clickable.bind(null, {inTab: true, inBackground: true})
490
491 commands.follow_in_focused_tab =
492 helper_follow_clickable.bind(null, {inTab: true, inBackground: false})
493
494 commands.follow_in_window = ({vim}) ->
495 callback = (marker) ->
496 vim._focusMarkerElement(marker.wrapper.elementIndex)
497 {href} = marker.wrapper
498 vim.window.openLinkIn(href, 'window', {}) if href
499 helper_follow('follow_in_tab', vim, callback)
500
501 commands.follow_multiple = (args) ->
502 args.count = Infinity
503 commands.follow(args)
504
505 commands.follow_copy = ({vim}) ->
506 callback = (marker) ->
507 {elementIndex} = marker.wrapper
508 property = switch marker.wrapper.type
509 when 'link'
510 'href'
511 when 'text'
512 'value'
513 when 'contenteditable', 'other'
514 'textContent'
515 vim._run('copy_marker_element', {elementIndex, property})
516 helper_follow('follow_copy', vim, callback)
517
518 commands.follow_focus = ({vim}) ->
519 callback = (marker) ->
520 vim._focusMarkerElement(marker.wrapper.elementIndex, {select: true})
521 helper_follow('follow_focus', vim, callback)
522
523 commands.click_browser_element = ({vim}) ->
524 markerElements = []
525
526 filter = ({markEverything}, element, getElementShape) ->
527 document = element.ownerDocument
528 semantic = true
529 type = switch
530 when vim._state.scrollableElements.has(element)
531 'scrollable'
532 when utils.isFocusable(element) or
533 (element.onclick and element.localName != 'statuspanel')
534 'clickable'
535
536 if markEverything and not type
537 type = 'other'
538 semantic = false
539
540 return unless type
541 return unless shape = getElementShape(element)
542 length = markerElements.push(element)
543 return {type, semantic, shape, elementIndex: length - 1}
544
545 callback = (marker) ->
546 element = markerElements[marker.wrapper.elementIndex]
547 switch marker.wrapper.type
548 when 'scrollable'
549 utils.focusElement(element, {flag: 'FLAG_BYKEY'})
550 when 'clickable', 'other'
551 sequence =
552 if element.localName == 'tab'
553 ['mousedown']
554 else
555 'click-xul'
556 utils.focusElement(element)
557 utils.simulateMouseEvents(element, sequence)
558
559 createMarkers = ({wrappers, viewport}) ->
560 {markers} = hints.injectHints(vim.window, wrappers, viewport, {
561 hint_chars: vim.options.hint_chars
562 ui: true
563 })
564 return markers
565
566 result = hints.getMarkableElementsAndViewport(
567 vim.window, filter.bind(null, {markEverything: false})
568 )
569
570 if result.wrappers.length > 0
571 storage = vim.enterMode('hints', createMarkers(result), callback)
572 storage.markEverything = ->
573 newResult = hints.getMarkableElementsAndViewport(
574 vim.window, filter.bind(null, {markEverything: true})
575 )
576 storage.markers = createMarkers(newResult)
577 else
578 vim.notify(translate('notification.follow.none'))
579
580 helper_follow_pattern = (type, {vim}) ->
581 options = {
582 pattern_selector: vim.options.pattern_selector
583 pattern_attrs: vim.options.pattern_attrs
584 patterns: vim.options["#{type}_patterns"]
585 }
586 vim._run('follow_pattern', {type, options})
587
588 commands.follow_previous = helper_follow_pattern.bind(null, 'prev')
589
590 commands.follow_next = helper_follow_pattern.bind(null, 'next')
591
592 commands.focus_text_input = ({vim, count}) ->
593 vim.markPageInteraction()
594 vim._run('focus_text_input', {count})
595
596
597
598 findStorage = {lastSearchString: ''}
599
600 helper_find = ({highlight, linksOnly = false}, {vim}) ->
601 helpSearchInput = help.getSearchInput(vim.window)
602 if helpSearchInput
603 helpSearchInput.select()
604 return
605
606 helper_mark_last_scroll_position(vim)
607 findBar = vim.window.gBrowser.getFindBar()
608
609 mode = if linksOnly then findBar.FIND_LINKS else findBar.FIND_NORMAL
610 findBar.startFind(mode)
611 utils.focusElement(findBar._findField, {select: true})
612
613 return if linksOnly
614 return unless highlightButton = findBar.getElement('highlight')
615 if highlightButton.checked != highlight
616 highlightButton.click()
617
618 commands.find = helper_find.bind(null, {highlight: false})
619
620 commands.find_highlight_all = helper_find.bind(null, {highlight: true})
621
622 commands.find_links_only = helper_find.bind(null, {linksOnly: true})
623
624 helper_find_again = (direction, {vim}) ->
625 findBar = vim.window.gBrowser.getFindBar()
626 if findStorage.lastSearchString.length == 0
627 vim.notify(translate('notification.find_again.none'))
628 return
629 helper_mark_last_scroll_position(vim)
630 findBar._findField.value = findStorage.lastSearchString
631 findBar.onFindAgainCommand(direction)
632 message = findBar._findStatusDesc.textContent
633 vim.notify(message) if message
634
635 commands.find_next = helper_find_again.bind(null, false)
636
637 commands.find_previous = helper_find_again.bind(null, true)
638
639
640
641 commands.window_new = ({vim}) ->
642 vim.window.OpenBrowserWindow()
643
644 commands.window_new_private = ({vim}) ->
645 vim.window.OpenBrowserWindow({private: true})
646
647 commands.enter_mode_ignore = ({vim}) ->
648 vim.enterMode('ignore', {type: 'explicit'})
649
650 # Quote next keypress (pass it through to the page).
651 commands.quote = ({vim, count = 1}) ->
652 vim.enterMode('ignore', {type: 'explicit', count})
653
654 commands.enter_reader_view = ({vim}) ->
655 button = vim.window.document.getElementById('reader-mode-button')
656 if not button?.hidden
657 button.click()
658 else
659 vim.notify(translate('notification.enter_reader_view.none'))
660
661 commands.reload_config_file = ({vim}) ->
662 vim._parent.emit('shutdown')
663 config.load(vim._parent, (status) -> switch status
664 when null
665 vim.notify(translate('notification.reload_config_file.none'))
666 when true
667 vim.notify(translate('notification.reload_config_file.success'))
668 else
669 vim.notify(translate('notification.reload_config_file.failure'))
670 )
671
672 commands.help = ({vim}) ->
673 help.injectHelp(vim.window, vim._parent)
674
675 commands.dev = ({vim}) ->
676 vim.window.DeveloperToolbar.show(true) # `true` to focus.
677
678 commands.esc = ({vim}) ->
679 vim._run('esc')
680 utils.blurActiveBrowserElement(vim)
681 vim.window.DeveloperToolbar.hide()
682 vim.window.gBrowser.getFindBar().close()
683 hints.removeHints(vim.window) # Better safe than sorry.
684
685 unless help.getSearchInput(vim.window)?.getAttribute('focused')
686 help.removeHelp(vim.window)
687
688
689
690 module.exports = {
691 commands
692 findStorage
693 }
Imprint / Impressum