1 { classes: Cc, interfaces: Ci, utils: Cu } = Components
3 utils = require 'utils'
4 { getPref } = require 'prefs'
16 # Navigate to the address that is currently stored in the system clipboard
18 vim.window.location.assign utils.readFromClipboard()
20 # Open new tab and navigate to the address that is currently stored in the system clipboard
22 if chromeWindow = utils.getRootWindow vim.window
23 if gBrowser = chromeWindow.gBrowser
24 gBrowser.selectedTab = gBrowser.addTab utils.readFromClipboard()
26 # Open new tab and focus the address bar
28 if chromeWindow = utils.getRootWindow vim.window
29 if gBrowser = chromeWindow.gBrowser
30 gBrowser.selectedTab = chromeWindow.gBrowser.addTab()
32 # Copy current URL to the clipboard
34 vim.markers = injectHints vim.window.document
35 if vim.markers.length > 0
36 # This callback will be called with the selected marker as argument
38 if url = marker.element.href
39 utils.writeToClipboard url
43 # Copy current URL to the clipboard
45 utils.writeToClipboard vim.window.location.toString()
47 # Reload the page, possibly from cache
49 vim.window.location.reload(false)
51 # Reload the page from the server
53 vim.window.location.reload(false)
55 # Scroll to the top of the page
57 vim.window.scrollTo(0, 0)
59 # Scroll to the bottom of the page
61 vim.window.scrollTo(0, vim.window.document.body.scrollHeight)
65 scroll_step = getPref 'scroll_step'
66 vim.window.scrollBy(0, scroll_step)
70 scroll_step = getPref 'scroll_step'
71 vim.window.scrollBy(0, -scroll_step)
75 vim.window.scrollBy(0, vim.window.innerHeight)
79 vim.window.scrollBy(0, -vim.window.innerHeight)
81 # Activate previous tab
83 if rootWindow = utils.getRootWindow vim.window
84 rootWindow.gBrowser.tabContainer.advanceSelectedTab(-1, true);
88 if rootWindow = utils.getRootWindow vim.window
89 rootWindow.gBrowser.tabContainer.advanceSelectedTab(1, true);
93 if rootWindow = utils.getRootWindow vim.window
94 rootWindow.gBrowser.tabContainer.selectedIndex = 0;
98 if rootWindow = utils.getRootWindow vim.window
99 itemCount = rootWindow.gBrowser.tabContainer.itemCount;
100 rootWindow.gBrowser.tabContainer.selectedIndex = itemCount - 1;
104 vim.window.history.back()
106 # Go forward in history
108 vim.window.history.forward()
112 if rootWindow = utils.getRootWindow vim.window
113 rootWindow.gBrowser.removeCurrentTab()
115 # Restore last closed tab
117 if rootWindow = utils.getRootWindow vim.window
118 ss = utils.getSessionStore()
119 if ss and ss.getClosedTabCount(rootWindow) > 0
120 ss.undoCloseTab rootWindow, 0
122 # Follow links with hint markers
124 vim.markers = injectHints vim.window.document
125 if vim.markers.length > 0
126 # This callback will be called with the selected marker as argument
128 marker.element.focus()
129 utils.simulateClick marker.element
133 # Follow links in a new Tab with hint markers
135 vim.markers = injectHints vim.window.document
136 if vim.markers.length > 0
137 # This callback will be called with the selected marker as argument
139 marker.element.focus()
140 utils.simulateClick marker.element, metaKey: true
146 showHelp vim.window.document
149 # Blur active element if it's editable. Other elements
150 # aren't blurred - we don't want to interfere with
151 # the browser too much
152 activeElement = vim.window.document.activeElement
153 if utils.isElementEditable activeElement
157 removeHints vim.window.document
159 hideHelp vim.window.document
160 # Finally enter normal mode
161 vim.enterNormalMode()
164 # Split command pipes into individual commands
165 commands = do (commands) ->
167 for keys, command of commands
168 for key in keys.split '|'
169 newCommands[key] = command
172 # Called in hints mode. Will process the char, update and hide/show markers
173 hintCharHandler = (vim, char) ->
174 for marker in vim.markers
175 marker.matchHintChar char
177 if marker.isMatched()
179 removeHints vim.window.document
180 vim.enterNormalMode()
183 exports.hintCharHandler = hintCharHandler
184 exports.commands = commands