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