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