Simon Lydell [Mon, 29 Feb 2016 12:50:48 +0000 (13:50 +0100)]
Harden the `f` commands
It sucks that you can't trust the DOM. It sucks that on rare occasions, pressing
`f` shows no hints, but still enters Hints mode, leaving a
“element.href.startsWith is not a function” (or similar) error in the browser
console.
This commit tries to harden against such cases, by never trusting DOM properties
or methods to exist and be of the correct type. CoffeeScripts `?` is awesome for
this.
Simon Lydell [Sun, 28 Feb 2016 15:55:23 +0000 (16:55 +0100)]
Streamline `vimfx.on` events
_Always_ pass an object with event-specific properties, instead of sometimes
passing data directly. This is more consistent, and more future-proof since it
allows passing additional data without breaking backwards compatibility.
Simon Lydell [Sun, 28 Feb 2016 15:24:41 +0000 (16:24 +0100)]
Simplify the `config_file_directory` pref
- Set it to a normal system path, and let Firefox add `file://` and handle
Windows paths.
- Expand path starting with `~/` or `~\` to the user's home directory.
Simon Lydell [Sat, 27 Feb 2016 16:39:30 +0000 (17:39 +0100)]
Fix mutation errors in some `f` commands
For example, `2f` is supposed to open the first link in a new background tab and
the second link in the current tab. However, both were opened in background tabs
due to accidental mutation.
Simon Lydell [Fri, 26 Feb 2016 14:17:42 +0000 (15:17 +0100)]
Only allow `<late>` in single-key shortcuts
Previously, it was allowed in any shortcut sequence, but it only made a
difference for the last character. It really only makes sense to use `<late>`
with singe-key shortcuts.
Simon Lydell [Fri, 26 Feb 2016 13:31:33 +0000 (14:31 +0100)]
Use `prefs.get` directly in events-frame.coffee
... instead of using `messageManager.get`. This avoids synchronous messages,
which is a good thing. It violates the nice principle of only using the parsed
options of the `vimfx` object, but it doesn't really matter right now since only
four prefs are used in events-frame.coffee and they need little to none parsing.
One could probably pass the entire `vimfx.options` object down to frame scripts
when they start up and send updates whenever it updates, but let's do that when
a need for it comes up.
Simon Lydell [Fri, 26 Feb 2016 08:55:14 +0000 (09:55 +0100)]
Save the focusType instead of getting it on every keydown
This is simpler and more efficient. Also, we were basically already storing the
current focusType, since the button uses it to grey out when a text is focused.
Config API changes:
- `match` objects no longer have a `focus` property. It has been replaced with
the `likelyConflict` property. (Theoretically a breaking change.)
- `vim.focusType` is now available and contains the current focus type.
- The `focusTypeChange` event now passes only the current `vim` object to
listeners, instead of an object of data. Use `vim.focusType` to get the new
focusType. (Theoretically a breaking change.)
> Fix "invokeListener is not a function" uncaught errors
The commit indeed solved the above problem, but apparently replaced it with
another. When `invokeListener` has been `null`ed out, a copy of it can try to
reference things that also have been `null`ed out. So instead of storing copies
of it, we now check if the function exists before calling it. Otherwise, simply
do nothing. This commit also applies this to _all_ places `invokeListener` is
used.
Simon Lydell [Wed, 24 Feb 2016 12:29:13 +0000 (13:29 +0100)]
Improve Ignore mode and the blacklist
When you reloaded the page or visited some other page in the same time while in
Ignore mode, you'd always end up in Normal mode (unless the newly loaded page
was blacklisted). Now, you stay in Ignore mode in that case. This lets you press
`i` and browse around in that tab in Ignore mode, without having to press `i`
again any time a full page reload is caused.
However, if Ignore mode was entered automatically because of the blacklist, it
is also exited as expected if you browse to a non-blacklisted page.
This new behavior is possible by tracking the "type" of the Ignore mode. There
are currently two types, 'explicit' and 'blacklist', which correspond to the
above two cases.
Simon Lydell [Wed, 24 Feb 2016 07:03:39 +0000 (08:03 +0100)]
Fix issues when updating VimFx
After having updated VimFx, trying to use the `f` command on toggle buttons
often failed. This was because the frame script message listeners from the old
version wasn't shut down properly, which resulted in there being _two_ listeners
for the message to simulate a click on an element. The effects of this was
especially noticeable on toggle buttons, because clicking a toggle button twice
is a no-op. That gave the impression of VimFx failing to simulate a click at
all.
I think this erraneous shutdown behavior must have been introduced in commit 24b701e9, which switched from a synchronous message passing to an asynchronous
one in bootstrap.coffee. Previously, the shutdown message listener for frame
scripts had to be added after a timeout. Since mentioned commit, that timeout is
added in the response callback for the mentioned asynchronous message, which
should make the timeout unnecessary, but the timeout was still kept in that
commit. It shouldn't matter, but somehow it does. Removing the timeout fixes the
double message listeners problem, and does not seem to re-introduce the problems
that were fixed be adding the timeout in the first place (commit ec3a4394).
Simon Lydell [Tue, 23 Feb 2016 08:13:46 +0000 (09:13 +0100)]
Fix `@popupPassThrough` for menus in frames
When a menu, such as a context menu is open, VimFx is automatically disabled to
allow using the access keys of the open menu, as well as pressing `<escape>` to
close the menu. However, this used not to work for the context menus in the
devtools and in about:config. Now it does.
This also fixes a bug where VimFx stopped being automatically disabled after
closing a sub-menu of a context menu.
Simon Lydell [Tue, 23 Feb 2016 07:54:42 +0000 (08:54 +0100)]
Treat everything in the devtools as adjustable
Many things in the devtools can be "adjusted" with the arrow keys. For example,
if you `console.log` an object you can click it to get an interactive inspection
tree of that object. The tree can be navigated using the arrow keys, but not if
you, for example, use the arrow keys for VimFx's scrolling commands. With this
commit, that is no longer a problem.
Simon Lydell [Sun, 21 Feb 2016 14:35:12 +0000 (15:35 +0100)]
Replace element `instanceof` checks with `.localName`
KISS.
Note: `instanceof` checks are still often useful for XUL elements, because some
interfaces are extended by several elements.
Also note that `.localName` is used instead of `.nodeName` because many XUL
pages embed HTML elements. When mixing namespaces like that, the `.nodeName`s of
HTML elements will start with `html:`, while `.localName` skips the prefix.
`.localName` also nicely always returns valid HTML node names in lowercase.
Simon Lydell [Mon, 22 Feb 2016 18:29:26 +0000 (19:29 +0100)]
Split `gl` into `gl` and `gL`
`gl` selects the most recent tab. Simple, right? But what if you open a
background tab? Which is the most recent tab now? Or if you open several
background tabs?
Previously, if you opened several background tabs and then pressed `gl`, the
last opened new background tab would be selected. That behavior just happened to
be.
In my opinion, it is more consistent if `gl` always selects the last _visited_
tab. An unread background tab has _not_ been visited (yet). This commit makes
this change.
If there is only one visited tab (but possibly several unread tabs), a
notification is shown telling that there is no most recent tab.
The `gL` command selects the oldest unread tab. This is useful when having
opened a bunch of background tabs. `gL` then lets you step them through in the
order you opened them. (If there are no unread tabs, a notification is shown.)
In other words, `gl` deals with _visited_ tabs only (from now on), while `gL`
deals with _unread_ tabs only.
The motivation for this commit came from piroor/treestyletab#874.
Mentioned commit attempted to fix a problem where `vim.mode` could be
`undefined` in some `vimfx.on(...)` listeners. The button uses such an event
listener, and uses `vim.mode` in the key for a `translate(key)` call, which
caused `translate` to throw an error. This was because `vim.mode` wasn't set
until after a timeout. The fix was to emit the events after the same timeout.
However, the above solution is very unreliable, and the problem still slipped
through every now and then.
The reason the first timeout was added in the first place was to allow calling
`vimfx.getCurrentVim()` inside `vimfx.on(...)` listeners. This commit removes
both timeouts, while still preserving that behavior by splitting the contructor
of `Vim` into a new method, `._start`. This should be bullet-proof, less hacky
and faster.
Simon Lydell [Sun, 21 Feb 2016 14:05:49 +0000 (15:05 +0100)]
Add partial support for the wasavi extension
It's editor is now recognized as an editable element, but pressing `<escape>` in
its insert mode still blurs the editor instead of exiting its insert mode.
(`<escape>`) should ideally only blur in wasavi's normal mode.
- `element.style.zIndex`: Always string.
- `element.style.zIndex = value`: Turns `value` into a string.
- `a = '5'; a++`: `a` is now `6`.
- `element.style.zIndex++`: If the previous value was `'5'`, the new value is
`'6'`. This method was used before above commit.
- `element.style.zIndex += 1`: If the previous value was `'5'`, the new value is
`'51'`. This was introduced by above commit.
The above really shows that you should always be explicit about types. Since
`element.style.zIndex` is always a string, `element.style.zIndex++` was a
terrible hack that happened to work, but caused a bug when it was rewritten to
a seemingly equivalent expression.
This commit first reads the `z-index` of the element and explicitly makes it a
`Number`, allowing incrementing to work as expected.
Simon Lydell [Fri, 19 Feb 2016 06:55:41 +0000 (07:55 +0100)]
Reduce unnecessary vertical code alignment
While it may look nice many times, it causes annoying merge conflicts.
Especially aligning all `require(...)` calls has bitten me many times, since
adding or removing one often requires reformatting the entire block.
This commit attempts to remove vertical alignment (especially around `=`) for
the sake of smaller diffs and simpler merges.
Vertical alignment has been kept, though, where it really makes the code easier
to read and you're likely to edit all of the aligned lines anyway if changing
one of them. The most common example is code dealing with X and Y coordinates
and having to do the same thing to both of them. Only the words X, Y, left,
right, top, bottom, width, height etc. differ between the lines. It's easier to
see that they are really up-to-date with each other if the common parts are
aligned.
Simon Lydell [Thu, 28 Jan 2016 21:05:54 +0000 (22:05 +0100)]
Rework programmatic customization of VimFx
- The public API has been removed. While the idea of allowing other extensions
to extend VimFx is neat, I don't think it'll ever be used. KISS. As a
replacement, the config files have become more top-notch.
- The former public API is now the config file API.
- Config files are no longer regular add-ons. We used to provide a boilerplate
for such an add-on, which consisted of a bunch of files users most likely
wouldn't touch as well as `config.js` and `frame.js`. Now, the concept of
`config.js` and `frame.js` has been kept, but they are loaded directly, if the
path to their parent directory is given in the `config_file_directory` pref.
This is much easier and simpler, and does not require the user to install a
version of Firefox with the ability to install unsign add-ons (or having to go
through the hassle of actually signing the "config file add-on").
- `zr` reloads the config file(s). This is possible because of the above point
and is much nicer than having to restart Firefox every time you change your
config (or setting up something like the Extension Auto-Installer).
- `vimfx.send(...)` and `vimfx.listen(...)` have been added, to make it easier
to create custom commands that interact with web page content, which is quite
common. These are basically `messageManager.send` and `messageManager.listen`.
To make the API simpler, instead of passing the name of the callback message
to listeners and having to do `messageManager.send(callback, data)` to respond
to a message, a real callback _function_ is now passed instead, which does the
message sending behind the scenes. This also resulted in some nice code
cleanup overall.
- `vimfx.off(...)` has been added, to remove `vimfx.on(...)` listeners. This is
mostly used internally. Since `zr` allows reloading the config file,
everything in it must be undoable.
- By loading `frame.js` directly, it is now possible to pass a real API to it,
rather than relying on `VimFx*` properties on the global frame script object.
- The new, "real" frame script API now has tests. This involved adding support
for running tests in frame scripts.
Simon Lydell [Sat, 6 Feb 2016 16:52:18 +0000 (17:52 +0100)]
Improve and add more documentation
- Improved wording and consistency.
- Add short summaries of each section in the table of contents.
- Document how to install VimFx. Fixes #686.
- Document modes.
- Don't refer to the "Public API" anymore, but the "config file API". It is no
longer intended to be used by other add-ons. (The plan is to load config files
in a different way in the future.)
Simon Lydell [Sat, 6 Feb 2016 17:22:42 +0000 (18:22 +0100)]
Improve CONTRIBUTING.md
- Remove "Use English". That's understood since the bug template is in English.
- Put the instruction about bugs at the top.
- Make the paragraph about the changelog a bullet point. It makes the
instructions look shorter. Since the "Use English" bullet point was removed,
the list does not look too long either.
- Move the "Contributing code?" link off to the right to get it out of the way.
- Use fewer words in a few places. The less to read the better.
Also: Link to CONTRIBUTING.md instead of directly to the issue tracker in the
readme, to increase the chance of people actually reading it. Therefore a "Go to
the issue tracker" link was added in CONTRIBUTING.md (it goes to the issues
list, not a new issue, to increase the chance of people looking for duplicates).
Simon Lydell [Wed, 3 Feb 2016 17:11:33 +0000 (18:11 +0100)]
Make the `H` and `L` commands more reliable
It seems like using `window.BrowserBack()` and `window.BrowserForward()` are the
most reliable ways of navigating the history, rather than having to wait for
`SessionStore.getSessionHistory()` to finish and then going to a certain history
index. This commit optimizes the case where the count is 1 to use the mentioned
functions instead. Some extensions also override those, so calling them results
in better interoperability.
(Hopefully/Likely) fixes #687.
To keep the code changes simple, the support for Firefox < 43 was dropped.
That's fine, since Firefox 44 has already been released.
Simon Lydell [Tue, 26 Jan 2016 21:50:10 +0000 (22:50 +0100)]
Use async messaging in bootstrap.coffee
The initial message from new frame scripts is now async. This is possible since
commit bd00a85e0. Other than following the recommendation to avoid sync
messaging whenever possible, this fixes #679 and fixes #624.
Simon Lydell [Tue, 26 Jan 2016 18:41:38 +0000 (19:41 +0100)]
Use strings instead of functions in the `modes` object
Since we run things properly in the `startup()` function of bootstrap.js since
last commit, the `chrome://` URI to the string bundles is now available when the
`modes` object is constructed. This means that there's no need anymore to let
mode names, category names and command descriptions be functions. Instead they
can be the sane thing: Simply strings.
Note that this is a backwards incompatible change. Luckily it does not affect
the `.addCommand()` API method, so propably won't impact anyone.
Simon Lydell [Tue, 26 Jan 2016 18:15:05 +0000 (19:15 +0100)]
Use `chrome://` URIs for `require()` calls
Apparently, `chrome://` URIs registered in chrome.manifest cannot be used in
bootstrap.js until its `startup()` function is called. Therefore this commit
reorganizes the code of bootstrap.coffee a bit, so that actual work is done
inside `startup()` (where it is supposed to be, after all). Outside of that
function we now mostly simply declare variables that the `shutdown()` function
needs to access as well. Some things were moved into main.coffee as well.
- Using `chrome://` URIs is the way add-ons are "supposed" to do it.
- If a `require()` call fails, we now get much shorter URIs in the error
message, making things easier to debug.
- This allows to get rid of the hack of sending `__SCRIPT_URI_SPEC__` to frame
scripts.
Simon Lydell [Tue, 26 Jan 2016 07:31:39 +0000 (08:31 +0100)]
Improve CPU usage in Hints mode
Raising the "check for marker element movements" interval from 0 to 15 results
in no noticeable CPU usage change on my system, while still allowing markers to
move smoothly. Setting it to 20 results in noticeable stutter.
This commit also add the `hints_sleep` pref to control the interval, or disable
the feature altogether.
Additionally, the interval now doesn't run at all for the `zF` command.
Previously, it ran as usual, but didn't do anything (as marker movement isn't
supported (YAGNI) for the `zF` command).
The "real" tab elements are the rectangles to the left of the dotted vertical
lines. The triangle parts are made using the `::before` or `::after`
pseudo-elements of the tabs.
When calling `.elementFromPoint()` on a pseudo-element, its parent element is
returned. But calling `.getBoundingClientRect()` on the parent element returns a
rectangle only around the the parent element, excluding the pseudo-element.
Because of the pseudo-elements overlap the next tab, the second tab is
considered covered by the first tab.
Previously, a point to the right of the first tab would then be tried. But since
the pseudo-element isn't included in `.getBoundingClientRect()` that would mean
the point marked with a `+`, which is actually to the _left_ of the original
point, not to the right! That obviously didn't work.
With this commit, if the "try-right point" is to the left of the initial point
and the covering element and the queried element are in the same frame, the
point is tried again but this time forcing the element to be considered located
at that point, solving the issue.
Using pseudo-elements to create non-rectangular tabs is quite common, so this
will help on other sites as well.
Simon Lydell [Sun, 24 Jan 2016 09:22:55 +0000 (10:22 +0100)]
Remove check for 'close' class for clickable elements
It gave too many false positives because of the word 'closed' in many classes.
Instead of trying to switch to a regex to avoid those cases, I'm trying to
completely remove the check. Hopefully the other matching rules are enough.
Simon Lydell [Sat, 23 Jan 2016 18:31:37 +0000 (19:31 +0100)]
Remove hints and help on shutdown
Previously, if you disabled VimFx by using the `f` command to click VimFx's
"Disable" button in the Add-ons Manager, the hint markers would be left behind
(though losing their styling). This meant that the entire page would be covered
by a transparent element impossible to remove (other than closing the tab) and
impossible to click through.
A similar thing happened if you left the help dialog open in another tab while
disabling VimFx.
This commit makes sure that both those pieces of UI are removed on shutdown.
Simon Lydell [Thu, 21 Jan 2016 06:47:18 +0000 (07:47 +0100)]
Recognize more elements as clickable
- Elements with `data-` attributes used for clickable things by Bootstrap are
now recognized. This is a huge win since Bootstrap is very popular and many
developers use it with semantically unclickable elements (even though the
Bootstrap documentation always reminds of accessibility concerns). Since these
elements are or _should have been_ semantically clickable elements, they are
always treated as such, in order not to give them too bad hints.
- A few `aria-` attributes are now recognized as semantically clickable.
- ARIA roles are now treated as _semantically_ clickable, instead of just
clickable.
- "Close" buttons are now attempted to be recognized. This is useful for many of
those obtrusive EU cookie law notices. Recognizing Bootstrap elements also
helps greatly here.
- Finally, elements with 'click' event listeners (added using
`element.addEventListener('click', ...)`) are now recognized, by using a
Firefox API. This is really useful on DuckDuckGo's image search. Fixes #671
and fixes #672.
Note that event delegation is not supported, since that would require
inspecting the code of the event listeners. One _could_ inspect the global
`jQuery` object (if any) to get to solve that problem to a great extent (like
Firefox's devtools do), but I'm not sure if that's a good idea.
It should also be noted that I tried recognizing elements matching
`/\bjs-/.test(element.className)`, but that proved give too many false
positives.
Simon Lydell [Fri, 22 Jan 2016 06:40:01 +0000 (07:40 +0100)]
Never prevent autofocus in XUL pages
- Every time I go to `about:config` I wish that the filter field was focused.
- Even though `vim.markPageInteraction()` was called, the "click to go to
command" feature of the help dialog sometimes failed to autofocus the text
input for the command.
Thus, I think it's sensible to simply _not_ prevent autofocus in XUL pages. Such
pages are few and well-behaved (it seems).
Simon Lydell [Thu, 21 Jan 2016 16:34:04 +0000 (17:34 +0100)]
Improve autofocus prevention after `[` and `]`
When you go to the next page of GitHub’s code search results, the page is loaded
with AJAX. GitHub then annoyingly focuses its search input. This autofocus
cannot be prevented in a reliable way, because the case is indistinguishable
from a button whose job is to focus some text input. However, after the `[` and
`]` command we know for sure that we can prevent the next focus. This commit
resets the `vim.state.hasInteraction` flag in those commands to allow for this
behavior, by adding the `value=true` parameter to `vim.markPageInteraction()`
and passing in `false`.