diff --git a/package-lock.json b/package-lock.json index 3bfeb3c4a..ff2e2a350 100644 --- a/package-lock.json +++ b/package-lock.json @@ -57,7 +57,6 @@ "hast-util-to-dom": "^4.0.1", "js-yaml": "^5.2.1", "katex": "^0.17.0", - "keyux": "^0.11.6", "lodash": "^4.18.1", "lru-cache": "^11.5.2", "marked": "^18.0.6", @@ -3418,22 +3417,6 @@ "katex": "cli.js" } }, - "node_modules/keyux": { - "version": "0.11.6", - "resolved": "https://registry.npmjs.org/keyux/-/keyux-0.11.6.tgz", - "integrity": "sha512-sibuRm9zix1VixIAk7KWr78eEpuA34F2wKaorP8vHnqLn7W8hZRBYlBDUUw37OCbnuXQhi61/bYhAiUnxXrhow==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "license": "MIT", - "engines": { - "node": "^20.0.0 || ^22.0.0 || >=24.0.0" - } - }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", diff --git a/package.json b/package.json index 4784bd711..ebe805e59 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,6 @@ "hast-util-to-dom": "^4.0.1", "js-yaml": "^5.2.1", "katex": "^0.17.0", - "keyux": "^0.11.6", "lodash": "^4.18.1", "lru-cache": "^11.5.2", "marked": "^18.0.6", diff --git a/src/App.svelte b/src/App.svelte index 657430ae8..32d76a6cd 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -17,25 +17,36 @@ import { nodeRunning } from "@app/lib/events"; import { dynamicInterval } from "@app/lib/interval"; import { invoke } from "@app/lib/invoke"; - import { hide, toggle } from "@app/lib/modal"; + import { hide, modalStore, show, toggle } from "@app/lib/modal"; import * as router from "@app/lib/router"; - import { isLoadedRepoRoute } from "@app/lib/router/definitions"; - import { toggleSidebar } from "@app/lib/sidebar.svelte"; + import { + isLoadedRepoRoute, + sidebarDataOf, + } from "@app/lib/router/definitions"; + import { sidebarCollapsed, toggleSidebar } from "@app/lib/sidebar.svelte"; import { setUnlistenNodeEvents, unlistenNodeEvents, } from "@app/lib/startup.svelte"; - import { isMac, unreachable } from "@app/lib/utils"; + import { isMac, isTyping, unreachable } from "@app/lib/utils"; import { dragWindow } from "@app/lib/window"; import AppSidebar from "@app/components/AppSidebar.svelte"; import { codeFont } from "@app/components/CodeFontSwitch.svelte"; + import { openListSearch } from "@app/components/FuzzySearch.svelte"; + import { + isRepoFilter, + openRepoFilter, + sidebarRepoOrder, + } from "@app/components/SidebarRepoList.svelte"; import { followSystemTheme, loadTheme, theme, } from "@app/components/ThemeSwitch.svelte"; + import CreateIssueModal from "@app/modals/CreateIssue.svelte"; import GuideView from "@app/modals/Guide.svelte"; + import KeyboardShortcutsModal from "@app/modals/KeyboardShortcuts.svelte"; import SettingsView from "@app/modals/Settings.svelte"; import Auth from "@app/views/auth/Auth.svelte"; import CreateIdentity from "@app/views/auth/CreateIdentity.svelte"; @@ -61,6 +72,14 @@ return isLoadedRepoRoute(route) ? route.params.repo : undefined; }); + function modalHasTextEntry(): boolean { + return ( + document.querySelector( + "[data-modal-content] :is(textarea, [contenteditable='true'], input:not([type='checkbox'], [type='radio'], [type='range'], [type='button']))", + ) !== null + ); + } + window .matchMedia("(prefers-color-scheme: dark)") .addEventListener("change", ({ matches }) => { @@ -149,21 +168,86 @@ onkeydown={e => { const auxiliarKey = isMac() ? e.metaKey : e.ctrlKey; // Handles the position of the plus key on different keyboard layouts. - const plusKey = e.key === "1" || e.key === "="; + const plusKey = e.key === "+" || e.key === "="; + const backKey = isMac() + ? e.metaKey && e.key === "[" + : e.altKey && e.key === "ArrowLeft"; + const forwardKey = isMac() + ? e.metaKey && e.key === "]" + : e.altKey && e.key === "ArrowRight"; + const noModal = $modalStore === undefined; if (e.key === "Escape") { hide(); - } else if (auxiliarKey && (e.key === "+" || plusKey)) { + return; + } + // The first press goes to the sidebar's repo filter, the second one from + // there to the search of the list on screen. + if (auxiliarKey && e.key.toLowerCase() === "f" && noModal) { + if (isRepoFilter(e.target)) { + if (openListSearch()) { + e.preventDefault(); + } + } else if (!isTyping(e.target)) { + e.preventDefault(); + if (sidebarCollapsed.value) { + openListSearch(); + } else { + openRepoFilter(); + } + } + return; + } + if (isTyping(e.target)) { + return; + } + if (auxiliarKey && plusKey) { increaseFontSize(); } else if (auxiliarKey && e.key === "-") { decreaseFontSize(); } else if (auxiliarKey && e.key.toLowerCase() === "0") { resetFontSize(); + } else if (auxiliarKey && e.key.toLowerCase() === "r") { + e.preventDefault(); + // A reload would throw away whatever is being composed in a modal. + if (!modalHasTextEntry()) { + // Matches the sidebar's reload button rather than re-fetching per route. + window.location.reload(); + } + } else if (auxiliarKey && /^[1-9]$/.test(e.key) && noModal) { + const repos = sidebarDataOf($activeRouteStore)?.repos; + const repo = repos && sidebarRepoOrder(repos)[Number(e.key) - 1]; + if (repo) { + e.preventDefault(); + void router.push({ resource: "repo.home", rid: repo.rid }); + } + } else if (backKey && noModal) { + e.preventDefault(); + window.history.back(); + } else if (forwardKey && noModal) { + e.preventDefault(); + window.history.forward(); } else if (auxiliarKey && e.key === ",") { e.preventDefault(); toggle({ component: SettingsView, props: {} }); } else if (auxiliarKey && e.key.toLowerCase() === "b") { e.preventDefault(); toggleSidebar(); + } else if (e.key === "?" && !auxiliarKey && !e.altKey) { + // Only toggle our own modal, so an open modal isn't replaced from + // under the user. + const open = $modalStore?.component; + if (open === undefined || open === KeyboardShortcutsModal) { + e.preventDefault(); + toggle({ component: KeyboardShortcutsModal, props: {} }); + } + } else if ( + auxiliarKey && + e.key.toLowerCase() === "n" && + activeRepo && + noModal + ) { + e.preventDefault(); + show({ component: CreateIssueModal, props: { repo: activeRepo } }); } }} /> diff --git a/src/components/FullscreenModalPortal.svelte b/src/components/FullscreenModalPortal.svelte index c3b85958f..16ec28be2 100644 --- a/src/components/FullscreenModalPortal.svelte +++ b/src/components/FullscreenModalPortal.svelte @@ -1,4 +1,6 @@ + {#if hasItems} {#if show} { @@ -64,7 +101,7 @@ {styleHeight} keyShortcuts="ctrl+f" onclick={() => (show = true)}> - + {/if} diff --git a/src/components/InboxList.svelte b/src/components/InboxList.svelte index e71b0c931..604730002 100644 --- a/src/components/InboxList.svelte +++ b/src/components/InboxList.svelte @@ -253,7 +253,7 @@ diff --git a/src/components/SidebarRepoList.svelte b/src/components/SidebarRepoList.svelte index b42e9f0bd..12ea1d68d 100644 --- a/src/components/SidebarRepoList.svelte +++ b/src/components/SidebarRepoList.svelte @@ -1,4 +1,6 @@ + + + + diff --git a/src/modals/Settings.svelte b/src/modals/Settings.svelte index f5a85e40f..98a3e2e78 100644 --- a/src/modals/Settings.svelte +++ b/src/modals/Settings.svelte @@ -6,7 +6,6 @@ import { diffOptions } from "@app/lib/diffOptions.svelte"; import { hints } from "@app/lib/hints"; import { invoke } from "@app/lib/invoke"; - import { hide } from "@app/lib/modal"; import { updateChecker } from "@app/lib/updateChecker.svelte"; import { pluralize } from "@app/lib/utils"; @@ -77,7 +76,6 @@ .header { display: flex; align-items: center; - justify-content: space-between; padding: 0 1.5rem; height: 3.25rem; flex-shrink: 0; @@ -129,11 +127,6 @@