Add attempt at context menu hint mode

This commit is contained in:
Oliver Blanthorn 2019-10-13 10:37:19 +01:00
parent 9ccd23d00c
commit 958bc855a0
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 16 additions and 1 deletions

View file

@ -3680,6 +3680,7 @@ export function unset(...keys: string[]) {
- -# yank an element's anchor URL to clipboard
- -c [selector] hint links that match the css selector
- `bind ;c hint -c [class*="expand"],[class="togg"]` works particularly well on reddit and HN
- -C open context menu
- -f [text] hint links and inputs that display the given text
- `bind <c-e> hint -f Edit`
- -fr [text] use RegExp to hint the links and inputs
@ -3950,6 +3951,17 @@ export async function hint(option?: string, selectors?: string, ...rest: string[
)
break
case "-C":
selectHints = hinting.pipe_elements(
hinting.hintables(selectors),
elem => {
DOM.mouseEvent(elem,"context")
return elem
},
rapid,
)
break
case "-r":
selectHints = hinting.pipe_elements(
DOM.elementsWithText(),

View file

@ -91,7 +91,7 @@ function isEditableHTMLInput(element: HTMLInputElement) {
*/
export function mouseEvent(
element: Element,
type: "hover" | "unhover" | "click",
type: "hover" | "unhover" | "click" | "context",
modifierKeys = {},
) {
let events = []
@ -104,6 +104,9 @@ export function mouseEvent(
case "hover":
events = ["mouseover", "mouseenter", "mousemove"].concat(events)
break
case "context":
events = ["contextmenu"]
break
}
events.forEach(type => {
const event = new MouseEvent(type, {