3 { classes: Cc, interfaces: Ci, utils: Cu } = Components
5 utils = require 'utils'
13 # Navigate to the address that is currently stored in the system clipboard
15 vim.window.location.assign utils.readFromClipboard()
17 # Open new tab and navigate to the address that is currently stored in the system clipboard
19 if chromeWindow = utils.getRootWindow vim.window
20 if gBrowser = chromeWindow.gBrowser
21 gBrowser.selectedTab = gBrowser.addTab utils.readFromClipboard()
23 # Open new tab and focus the address bar
25 if chromeWindow = utils.getRootWindow vim.window
26 if gBrowser = chromeWindow.gBrowser
27 gBrowser.selectedTab = chromeWindow.gBrowser.addTab()
29 # Copy current URL to the clipboard
31 vim.markers = injectHints vim.window.document,
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 # This callback will be called with the selected marker as argument
121 marker.element.focus()
122 utils.simulateClick marker.element
126 # Follow links in a new Tab with hint markers
128 vim.markers = injectHints vim.window.document,
129 # This callback will be called with the selected marker as argument
131 marker.element.focus()
132 utils.simulateClick marker.element, metaKey: true
137 # Blur active element if it's editable. Other elements
138 # aren't blurred - we don't want to interfere with
139 # the browser too much
140 activeElement = vim.window.document.activeElement
141 if utils.isElementEditable activeElement
144 # Remove hints and enter normal mode
145 removeHints vim.window.document
146 vim.enterNormalMode()
148 hintCharHandler = (vim, char) ->
150 for hint, marker of vim.markers
151 count = marker.matchHintChar char
152 maxCount = Math.max count, maxCount
154 for hint, marker of vim.markers
155 if marker.matchedHintCharCount == marker.hintChars.length == maxCount
156 console.log marker.hintChars
158 removeHints vim.window.document
159 vim.enterNormalMode()
162 if marker.matchedHintCharCount < maxCount
167 exports.hintCharHandler = hintCharHandler
168 exports.commands = do ->
170 for keys, command of commands
171 for key in keys.split '|'
172 newCommands[key] = command