]> git.gir.st - VimFx.git/blob - extension/packages/commands.coffee
Closes #5. Created simple build script. The extension contents are moved into
[VimFx.git] / extension / packages / commands.coffee
1 { classes: Cc, interfaces: Ci, utils: Cu } = Components
2
3 utils = require 'utils'
4 { getPref } = require 'prefs'
5
6 { handleHintChar
7 , injectHints
8 , removeHints
9 } = require 'hints'
10
11 { showHelp
12 , hideHelp
13 } = require 'help'
14
15 commands =
16 # Navigate to the address that is currently stored in the system clipboard
17 'p': (vim) ->
18 vim.window.location.assign utils.readFromClipboard()
19
20 # Open new tab and navigate to the address that is currently stored in the system clipboard
21 'P': (vim) ->
22 if chromeWindow = utils.getRootWindow vim.window
23 if gBrowser = chromeWindow.gBrowser
24 gBrowser.selectedTab = gBrowser.addTab utils.readFromClipboard()
25 #
26 # Open new tab and focus the address bar
27 't': (vim) ->
28 if chromeWindow = utils.getRootWindow vim.window
29 if gBrowser = chromeWindow.gBrowser
30 gBrowser.selectedTab = chromeWindow.gBrowser.addTab()
31
32 # Copy current URL to the clipboard
33 'y,f': (vim) ->
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
37 vim.cb = (marker) ->
38 if url = marker.element.href
39 utils.writeToClipboard url
40
41 vim.enterHintsMode()
42
43 # Copy current URL to the clipboard
44 'y,y': (vim) ->
45 utils.writeToClipboard vim.window.location.toString()
46
47 # Reload the page, possibly from cache
48 'r': (vim) ->
49 vim.window.location.reload(false)
50 #
51 # Reload the page from the server
52 'R': (vim) ->
53 vim.window.location.reload(false)
54
55 # Scroll to the top of the page
56 'g,g': (vim) ->
57 vim.window.scrollTo(0, 0)
58
59 # Scroll to the bottom of the page
60 'G': (vim) ->
61 vim.window.scrollTo(0, vim.window.document.body.scrollHeight)
62
63 # Scroll down a bit
64 'j|c-e': (vim) ->
65 scroll_step = getPref 'scroll_step'
66 vim.window.scrollBy(0, scroll_step)
67
68 # Scroll up a bit
69 'k|c-y': (vim) ->
70 scroll_step = getPref 'scroll_step'
71 vim.window.scrollBy(0, -scroll_step)
72
73 # Scroll down a page
74 'd|c-d': (vim) ->
75 vim.window.scrollBy(0, vim.window.innerHeight)
76
77 # Scroll up a page
78 'u|c-u': (vim) ->
79 vim.window.scrollBy(0, -vim.window.innerHeight)
80
81 # Activate previous tab
82 'J|g,T': (vim) ->
83 if rootWindow = utils.getRootWindow vim.window
84 rootWindow.gBrowser.tabContainer.advanceSelectedTab(-1, true);
85
86 # Activate next tab
87 'K|g,t': (vim) ->
88 if rootWindow = utils.getRootWindow vim.window
89 rootWindow.gBrowser.tabContainer.advanceSelectedTab(1, true);
90
91 # Go to the first tab
92 'g,H|g,0': (vim) ->
93 if rootWindow = utils.getRootWindow vim.window
94 rootWindow.gBrowser.tabContainer.selectedIndex = 0;
95 #
96 # Go to the last tab
97 'g,L|g,$': (vim) ->
98 if rootWindow = utils.getRootWindow vim.window
99 itemCount = rootWindow.gBrowser.tabContainer.itemCount;
100 rootWindow.gBrowser.tabContainer.selectedIndex = itemCount - 1;
101
102 # Go back in history
103 'H': (vim) ->
104 vim.window.history.back()
105
106 # Go forward in history
107 'L': (vim) ->
108 vim.window.history.forward()
109
110 # Close current tab
111 'x': (vim) ->
112 if rootWindow = utils.getRootWindow vim.window
113 rootWindow.gBrowser.removeCurrentTab()
114
115 # Restore last closed tab
116 'X': (vim) ->
117 if rootWindow = utils.getRootWindow vim.window
118 ss = utils.getSessionStore()
119 if ss and ss.getClosedTabCount(rootWindow) > 0
120 ss.undoCloseTab rootWindow, 0
121
122 # Follow links with hint markers
123 'f': (vim) ->
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
127 vim.cb = (marker) ->
128 marker.element.focus()
129 utils.simulateClick marker.element
130
131 vim.enterHintsMode()
132
133 # Follow links in a new Tab with hint markers
134 'F': (vim) ->
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
138 vim.cb = (marker) ->
139 marker.element.focus()
140 utils.simulateClick marker.element, metaKey: true
141
142 vim.enterHintsMode()
143
144 # Show Help
145 '?': (vim) ->
146 showHelp vim.window.document
147
148 'Esc': (vim) ->
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
154 activeElement.blur()
155
156 # Remove hints
157 removeHints vim.window.document
158 # Hide help dialog
159 hideHelp vim.window.document
160 # Finally enter normal mode
161 vim.enterNormalMode()
162
163
164 # Split command pipes into individual commands
165 commands = do (commands) ->
166 newCommands = {}
167 for keys, command of commands
168 for key in keys.split '|'
169 newCommands[key] = command
170 return newCommands
171
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
176
177 if marker.isMatched()
178 vim.cb marker
179 removeHints vim.window.document
180 vim.enterNormalMode()
181 break
182
183 exports.hintCharHandler = hintCharHandler
184 exports.commands = commands
Imprint / Impressum