diff --git a/app/app.vue b/app/app.vue index e1c314e7b..e199660a1 100644 --- a/app/app.vue +++ b/app/app.vue @@ -21,6 +21,8 @@ const localeMap = locales.value.reduce( {} as Record, ) +const commandBarRef = useTemplateRef('commandBarRef') + useHead({ htmlAttrs: { 'lang': () => locale.value, @@ -40,6 +42,11 @@ if (import.meta.server) { // "/" focuses search or navigates to search page // "?" highlights all keyboard shortcut elements function handleGlobalKeydown(e: KeyboardEvent) { + if (e.key === 'k' && (e.metaKey || e.ctrlKey)) { + e.preventDefault() + commandBarRef.value?.toggle() + } + if (isEditableElement(e.target)) return if (isKeyWithoutModifiers(e, '/')) { @@ -89,6 +96,7 @@ if (import.meta.client) {
+ diff --git a/app/components/CommandBar.vue b/app/components/CommandBar.vue new file mode 100644 index 000000000..993ffbf4d --- /dev/null +++ b/app/components/CommandBar.vue @@ -0,0 +1,241 @@ + + + + + diff --git a/app/components/Terminal/Install.vue b/app/components/Terminal/Install.vue index 37bd3441f..816c43a72 100644 --- a/app/components/Terminal/Install.vue +++ b/app/components/Terminal/Install.vue @@ -2,6 +2,8 @@ import type { JsrPackageInfo } from '#shared/types/jsr' import type { PackageManagerId } from '~/utils/install-command' +const { t } = useI18n() + const props = defineProps<{ packageName: string requestedVersion?: string | null @@ -93,6 +95,37 @@ const copyRunCommand = (command?: string) => copyRun(getFullRunCommand(command)) const { copied: createCopied, copy: copyCreate } = useClipboard({ copiedDuring: 2000 }) const copyCreateCommand = () => copyCreate(getFullCreateCommand()) + +registerScopedCommand({ + id: 'package:install', + name: t('command.copy_install'), + description: t('command.copy_install_desc'), + handler: async () => { + copyInstallCommand() + }, +}) + +if (props.executableInfo?.hasExecutable) { + registerScopedCommand({ + id: 'packages:copy-run', + name: t('command.copy_run'), + description: t('command.copy_run_desc'), + handler: async () => { + copyRunCommand() + }, + }) +} + +if (props.createPackageInfo) { + registerScopedCommand({ + id: 'packages:copy-create', + name: t('command.copy_create'), + description: t('command.copy_create_desc'), + handler: async () => { + copyCreateCommand() + }, + }) +}