From 71fbc93c035df262d29607b3786bbfd2eeb402d8 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 20 May 2025 15:43:31 -0700 Subject: [PATCH] popover_menus: Avoid jQuery sizzle extension :visible. Signed-off-by: Anders Kaseorg --- web/src/popover_menus.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/web/src/popover_menus.ts b/web/src/popover_menus.ts index a762e382f2..8dae6009ad 100644 --- a/web/src/popover_menus.ts +++ b/web/src/popover_menus.ts @@ -66,9 +66,9 @@ export function popover_items_handle_keyboard(key: string, $items?: JQuery): voi return; } - let index = $items.index($items.filter(":focus")); + const index = $items.index($items.filter(":focus")); - if (key === "enter" && index >= 0 && index < $items.length) { + if (key === "enter") { // This is not enough for some elements which need to trigger // natural click for them to work like ClipboardJS and follow // the link for anchor tags. For those elements, we need to @@ -77,14 +77,17 @@ export function popover_items_handle_keyboard(key: string, $items?: JQuery): voi return; } - if (index === -1) { - index = 0; - } else if ((key === "down_arrow" || key === "vim_down") && index < $items.length - 1) { - index += 1; - } else if ((key === "up_arrow" || key === "vim_up") && index > 0) { - index -= 1; + if ((key === "down_arrow" || key === "vim_down") && index !== -1) { + [...$items] + .slice(index + 1) + .find((item) => item.getClientRects().length) + ?.focus(); + } else if ((key === "up_arrow" || key === "vim_up") && index !== -1) { + [...$items] + .slice(0, index) + .findLast((item) => item.getClientRects().length) + ?.focus(); } - $items.eq(index).trigger("focus"); } export function focus_first_popover_item($items: JQuery | undefined, index = 0): void { @@ -173,8 +176,7 @@ export function get_popover_items_for_instance(instance: tippy.Instance): JQuery return undefined; } - // eslint-disable-next-line no-jquery/no-sizzle - return $current_elem.find("a, [tabindex='0']").filter(":visible"); + return $current_elem.find("a, [tabindex='0']"); } export function hide_current_popover_if_visible(instance: tippy.Instance | null): void {