3 { classes: Cc, interfaces: Ci, utils: Cu } = Components
5 utils = require 'utils'
12 # Navigate to the address that is currently stored in the system clipboard
14 vim.window.location.assign utils.readFromClipboard()
16 # Open new tab and navigate to the address that is currently stored in the system clipboard
18 if chromeWindow = utils.getRootWindow vim.window
19 if gBrowser = chromeWindow.gBrowser
20 gBrowser.selectedTab = gBrowser.addTab utils.readFromClipboard()
22 # Open new tab and focus the address bar
24 if chromeWindow = utils.getRootWindow vim.window
25 if gBrowser = chromeWindow.gBrowser
26 gBrowser.selectedTab = chromeWindow.gBrowser.addTab()
28 # Copy current URL to the clipboard
30 vim.markers = injectHints vim.window.document
31 if vim.markers.length > 0
32 # This callback will be called with the selected marker as argument
34 if url = marker.element.href
35 utils.writeToClipboard url
39 # Copy current URL to the clipboard
41 utils.writeToClipboard vim.window.location.toString()
43 # Reload the page, possibly from cache
45 vim.window.location.reload(false)
47 # Reload the page from the server
49 vim.window.location.reload(false)
51 # Scroll to the top of the page
53 vim.window.scrollTo(0, 0)
55 # Scroll to the bottom of the page
57 vim.window.scrollTo(0, vim.window.document.body.scrollHeight)
61 vim.window.scrollBy(0, SCROLL_AMOUNT)
65 vim.window.scrollBy(0, -SCROLL_AMOUNT)
69 vim.window.scrollBy(0, vim.window.innerHeight)
73 vim.window.scrollBy(0, -vim.window.innerHeight)
75 # Activate previous tab
77 if rootWindow = utils.getRootWindow vim.window
78 rootWindow.gBrowser.tabContainer.advanceSelectedTab(-1, true);
82 if rootWindow = utils.getRootWindow vim.window
83 rootWindow.gBrowser.tabContainer.advanceSelectedTab(1, true);
87 if rootWindow = utils.getRootWindow vim.window
88 rootWindow.gBrowser.tabContainer.selectedIndex = 0;
92 if rootWindow = utils.getRootWindow vim.window
93 itemCount = rootWindow.gBrowser.tabContainer.itemCount;
94 rootWindow.gBrowser.tabContainer.selectedIndex = itemCount - 1;
98 vim.window.history.back()
100 # Go forward in history
102 vim.window.history.forward()
106 if rootWindow = utils.getRootWindow vim.window
107 rootWindow.gBrowser.removeCurrentTab()
109 # Restore last closed tab
111 if rootWindow = utils.getRootWindow vim.window
112 ss = utils.getSessionStore()
113 if ss and ss.getClosedTabCount(rootWindow) > 0
114 ss.undoCloseTab rootWindow, 0
116 # Follow links with hint markers
118 vim.markers = injectHints vim.window.document
119 if vim.markers.length > 0
120 # This callback will be called with the selected marker as argument
122 marker.element.focus()
123 utils.simulateClick marker.element
127 # Follow links in a new Tab with hint markers
129 vim.markers = injectHints vim.window.document
130 if vim.markers.length > 0
131 # This callback will be called with the selected marker as argument
133 marker.element.focus()
134 utils.simulateClick marker.element, metaKey: true
139 # Blur active element if it's editable. Other elements
140 # aren't blurred - we don't want to interfere with
141 # the browser too much
142 activeElement = vim.window.document.activeElement
143 if utils.isElementEditable activeElement
146 # Remove hints and enter normal mode
147 removeHints vim.window.document
148 vim.enterNormalMode()
151 # Split command pipes into individual commands
152 commands = do (commands) ->
154 for keys, command of commands
155 for key in keys.split '|'
156 newCommands[key] = command
159 # Called in hints mode. Will process the char, update and hide/show markers
160 hintCharHandler = (vim, char) ->
161 for marker in vim.markers
162 marker.matchHintChar char
164 if marker.isMatched()
166 removeHints vim.window.document
167 vim.enterNormalMode()
170 exports.hintCharHandler = hintCharHandler
171 exports.commands = commands