]> git.gir.st - VimFx.git/blob - packages/commands.coffee
Hint markers fixed: backspacing works fine now, markers are also properly hid when...
[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
13 # Navigate to the address that is currently stored in the system clipboard
14 'p': (vim) ->
15 vim.window.location.assign utils.readFromClipboard()
16
17 # Open new tab and navigate to the address that is currently stored in the system clipboard
18 'P': (vim) ->
19 if chromeWindow = utils.getRootWindow vim.window
20 if gBrowser = chromeWindow.gBrowser
21 gBrowser.selectedTab = gBrowser.addTab utils.readFromClipboard()
22 #
23 # Open new tab and focus the address bar
24 't': (vim) ->
25 if chromeWindow = utils.getRootWindow vim.window
26 if gBrowser = chromeWindow.gBrowser
27 gBrowser.selectedTab = chromeWindow.gBrowser.addTab()
28
29 # Copy current URL to the clipboard
30 'y,f': (vim) ->
31 vim.markers = injectHints vim.window.document,
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 'c-d': (vim) ->
69 vim.window.scrollBy(0, vim.window.innerHeight)
70
71 # Scroll up a page
72 'c-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,^': (vim) ->
87 if rootWindow = utils.getRootWindow vim.window
88 rootWindow.gBrowser.tabContainer.selectedIndex = 0;
89 #
90 # Go to the last tab
91 'g,$': (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 # This callback will be called with the selected marker as argument
120 vim.cb = (marker) ->
121 marker.element.focus()
122 utils.simulateClick marker.element
123
124 vim.enterHintsMode()
125
126 # Follow links in a new Tab with hint markers
127 'F': (vim) ->
128 vim.markers = injectHints vim.window.document,
129 # This callback will be called with the selected marker as argument
130 vim.cb = (marker) ->
131 marker.element.focus()
132 utils.simulateClick marker.element, metaKey: true
133
134 vim.enterHintsMode()
135
136 'Esc': (vim) ->
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
142 activeElement.blur()
143
144 # Remove hints and enter normal mode
145 removeHints vim.window.document
146 vim.enterNormalMode()
147
148 hintCharHandler = (vim, char) ->
149 for hint, marker of vim.markers
150 marker.matchHintChar char
151
152 if marker.isMatched()
153 vim.cb marker
154 removeHints vim.window.document
155 vim.enterNormalMode()
156 break
157
158 exports.hintCharHandler = hintCharHandler
159 exports.commands = do ->
160 newCommands = {}
161 for keys, command of commands
162 for key in keys.split '|'
163 newCommands[key] = command
164 return newCommands
Imprint / Impressum