From 958bc855a023cbed1d14e29cc29c5e4a0a7186d0 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Sun, 13 Oct 2019 10:37:19 +0100 Subject: [PATCH] Add attempt at context menu hint mode --- src/excmds.ts | 12 ++++++++++++ src/lib/dom.ts | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/excmds.ts b/src/excmds.ts index 6de230d9..fd5529e8 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -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 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(), diff --git a/src/lib/dom.ts b/src/lib/dom.ts index 63662ae9..ca996846 100644 --- a/src/lib/dom.ts +++ b/src/lib/dom.ts @@ -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, {