Making hint mode less janky is achieved by not resetting hint mode when
a hint has been selected. New command line options, `-q*` where `*`
stands for any alread-existing flag, are added.
The global hint flow is as following:
- User goes into hint mode
- hint mode promise is created
- When a hint is selected, the corresponding action is performed (e.g.
opening a link, killing an element...)
- The result of the action is saved in the hint
- If we're not in rapid hint mode, modeState is reset, and the hint mode
promise is resolved with the result of the action as parameter
- If we're in rapid hint mode, modeState is not reset. Instead its
filter is reset and all its hints are displayed again.
- Rapid hint mode is only left on escape, and this means that the
promise will be rejected.
Rejecting the promise means that we can't pipe elements selected in hint
rapid hint mode to other commands. This makes sense because pursuing
execution of a pipe several times in parallel, on top of being possibly
hard to implement, would probably be confusing.
Instead of using a pipe in order to execute arbitrary commands in hint
mode, users can use `-qW excmd`. Contrary to the pipe, this makes clear that
the excmd will be executed multiple times, once per focused hint.
This way of handling rapid hint mode has the advantage of simplifying
the `hint` function. Now, instead of having to return a tuple with the
number of available hints, the function can just return the selected
element or whatever the command line arguments specifies it should
return.
Instead of returning null when no hint has been selected, hinting.pipe
will now return a promise that will be resolved once a hint has been
selected or rejected if hintstate is destroyed without a hint being
explicitly selected by the user or if there are no hints to select.
Promise rejection is then handled at the end of excmds.ts:hint(), as
suggested by bovine3dom on Riot.
On SVG pages, trying to open the commandline results in an error. We
attempted to log this error using logger.error, which in turn tried to
open the command line. Recursion ensued.
This is fixed by not using the logger to log these errors to the. A
better solution could be to have the logger use the notification API to
tell the user about errors that happen while logging errors, but this
would require a new permission, which we shouldn't ask for until a
solution to https://github.com/cmcaine/tridactyl/issues/788 and
https://github.com/cmcaine/tridactyl/issues/708 is found.
This fixes https://github.com/cmcaine/tridactyl/issues/879.
In hinting.ts, pipe() and pipe_elements() assumed that the resolve
function they passed to hintPage() would always be called, which wasn't
always the case (e.g. when a users goes into hint mode but presses
`<Esc>`).
This caused unresolved promises to linger in the tab. When the tab was
closed, an error was thrown about the message manager being
disconnected. This was caught by Tridactyl and displayed in the command
line.
We're fixing this bug by passing no-op functions as onSelect to
hintPage() and explicitly passing the resolve function. The resolve
function is then saved in HintState and called when destroying
HintState.
We parametrize reset() in order to be able to distinguish between resets
caused by a hint being selected and by the user pressing `<Esc>`. This
is necessary because we need to know when the function should resolve
the last focused hint and when it shouldn't.
We then add a bunch of null handling in excmds.ts:hint() in order to
make sure not to introduce other bugs.
This fixes https://github.com/cmcaine/tridactyl/issues/855.