From f62021633b601475f461550054e49deaa8478e6b Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 19 Oct 2022 23:07:01 -0700 Subject: [PATCH] Respect settings target and allow command override --- src/components/quicklaunch.jsx | 18 +++++++++++------- src/pages/index.jsx | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/quicklaunch.jsx b/src/components/quicklaunch.jsx index d40e50d0a..a78ed5981 100644 --- a/src/components/quicklaunch.jsx +++ b/src/components/quicklaunch.jsx @@ -1,28 +1,32 @@ import { useTranslation } from "react-i18next"; -import { useEffect, useState, useRef, useCallback } from "react"; +import { useEffect, useState, useRef, useCallback, useContext } from "react"; import classNames from "classnames"; import { resolveIcon } from "./services/item"; +import { SettingsContext } from "utils/contexts/settings"; + export default function QuickLaunch({servicesAndBookmarks, searchString, setSearchString, isOpen, close}) { const { t } = useTranslation(); + const { settings } = useContext(SettingsContext); const searchField = useRef(); const [results, setResults] = useState([]); const [currentItemIndex, setCurrentItemIndex] = useState(null); - function openCurrentItem() { + function openCurrentItem(newWindow) { const result = results[currentItemIndex]; - window.open(result.href, '_blank'); + window.open(result.href, newWindow ? "_blank" : settings.target ?? "_blank"); } const closeAndReset = useCallback(() => { close(false); setTimeout(() => { setSearchString(""); + setCurrentItemIndex(null); }, 200); // delay a little for animations - }, [close, setSearchString]); + }, [close, setSearchString, setCurrentItemIndex]); function handleSearchChange(event) { setSearchString(event.target.value.toLowerCase()) @@ -33,7 +37,7 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear closeAndReset(); } else if (event.key === "Enter" && results.length) { closeAndReset(); - openCurrentItem(); + openCurrentItem(event.metaKey); } else if (event.key === "ArrowDown" && results[currentItemIndex + 1]) { setCurrentItemIndex(currentItemIndex + 1); event.preventDefault(); @@ -47,9 +51,9 @@ export default function QuickLaunch({servicesAndBookmarks, searchString, setSear setCurrentItemIndex(parseInt(event.target?.dataset?.index, 10)); } - function handleItemClick() { + function handleItemClick(event) { closeAndReset(); - openCurrentItem(); + openCurrentItem(event.metaKey); } useEffect(() => { diff --git a/src/pages/index.jsx b/src/pages/index.jsx index bf64cc595..7a0fdb087 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -197,7 +197,7 @@ function Home({ initialSettings }) { useEffect(() => { function handleKeyDown(e) { if (e.target.tagName === "BODY") { - if (String.fromCharCode(e.keyCode).match(/(\w|\s)/g) && !(e. altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { + if (String.fromCharCode(e.keyCode).match(/(\w|\s)/g) && !(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { setSearching(true); } else if (e.key === "Escape") { setSearchString("");