-
Notifications
You must be signed in to change notification settings - Fork 334
Command Palette #13658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Command Palette #13658
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
23332e7
WIP: Command palette
somebody1234 47d43f5
Initial command palette implementation
somebody1234 96f1367
[CommandPalette] Adjust appearance
somebody1234 32d05f8
[CommandPalette] Properly reactive query
somebody1234 50a7b4f
[CommandPalette] Add icons
somebody1234 c0c2e06
[CommandPalette] Prevent opening CB when running command from Command…
somebody1234 6a253ba
[ts] Fix lockfile
somebody1234 5396d95
[CommandPalette] Remove handlers for Project View
somebody1234 be480a9
[CommandPalette] Show keybinds
somebody1234 80bbece
[CommandPalette] Adjust markup
somebody1234 fd20727
[CommandPalette] Adjust markup; hide when in Project View
somebody1234 f1d93e4
[CommandPalette] Add entries for settings pages
somebody1234 6507186
[CommandPalette] Address CR
somebody1234 e94af0e
[Changelog] Add entry
somebody1234 8288068
Merge branch 'develop' into wip/sb/command-palette
somebody1234 90a79d1
Merge branch 'develop' into wip/sb/command-palette
somebody1234 f34d4db
Merge branch 'develop' into wip/sb/command-palette
somebody1234 294e0a8
Partially address CR
somebody1234 2cd283c
[CommandPalette] Group actions; remove duplicate entries
somebody1234 1d22cab
Merge branch 'develop' into wip/sb/command-palette
somebody1234 b81afa8
[Settings/Billing] Use correct text
somebody1234 69e73bd
Fix
somebody1234 7580643
pnpm dedupe
somebody1234 67aa86c
oops
somebody1234 4c638b4
[CommandPalette] Add arrow keys for navigation
somebody1234 8a5f5a7
Navigate back to drive when selecting Drive context menu entries
somebody1234 1ee1dc7
Merge branch 'develop' into wip/sb/command-palette
somebody1234 7867c88
Remove `motion-v`
somebody1234 8d919ef
Merge branch 'develop' into wip/sb/command-palette
somebody1234 7f1b61a
Fix errors
somebody1234 972f52c
Merge branch 'develop' into wip/sb/command-palette
mergify[bot] 75de8ca
Merge branch 'develop' into wip/sb/command-palette
somebody1234 2066b66
Fix integration tests
somebody1234 64b46bb
Merge branch 'develop' into wip/sb/command-palette
somebody1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| <script setup lang="ts"> | ||
| import KeyboardShortcutReact from '#/pages/dashboard/components/KeyboardShortcut' | ||
| import { unsetModal } from '#/providers/ModalProvider' | ||
| import * as objects from '#/utilities/object' | ||
| import { useActionsStore, type Action } from '$/providers/actions' | ||
| import { useContainerData } from '$/providers/container' | ||
| import { commandPaletteBindings } from '@/bindings' | ||
| import SvgIcon from '@/components/SvgIcon.vue' | ||
| import { useEvent } from '@/composables/events' | ||
| import { registerHandlers } from '@/providers/action' | ||
| import { injectInteractionHandler } from '@/providers/interactionHandler' | ||
| import { reactComponent } from '@/util/react' | ||
| import { AnimatePresence, motion } from 'motion-v' | ||
| import { computed, ref, watchEffect } from 'vue' | ||
|
|
||
| const KeyboardShortcut = reactComponent(KeyboardShortcutReact) | ||
|
|
||
| const { findActions } = useActionsStore() | ||
| const containerData = useContainerData() | ||
| const interaction = injectInteractionHandler() | ||
|
|
||
| const visible = ref(false) | ||
| const query = ref('') | ||
| const input = ref<HTMLInputElement | null>(null) | ||
|
|
||
| const actionHandlers = registerHandlers({ | ||
| 'commandPalette.open': { | ||
| action: () => { | ||
| if (containerData.tab !== 'drive' && containerData.tab !== 'settings') return | ||
| visible.value = true | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| watchEffect(() => { | ||
| if (!input.value) return | ||
| if (visible.value) { | ||
| unsetModal() | ||
| input.value.focus() | ||
| interaction.setCurrent({ | ||
| cancel() { | ||
| visible.value = false | ||
| }, | ||
| end() { | ||
| visible.value = false | ||
| }, | ||
| }) | ||
| } else { | ||
| input.value.blur() | ||
| query.value = '' | ||
| } | ||
| }) | ||
|
|
||
| useEvent( | ||
| window, | ||
| 'keydown', | ||
| commandPaletteBindings.handler( | ||
| objects.mapEntries( | ||
| commandPaletteBindings.bindings, | ||
| (actionName) => actionHandlers[actionName].action, | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
| function trigger(action: Action | undefined) { | ||
| if (!action) return | ||
| visible.value = false | ||
| action.doAction() | ||
| } | ||
|
|
||
| const actions = computed(() => findActions(query)) | ||
| </script> | ||
|
|
||
| <template> | ||
| <AnimatePresence> | ||
| <motion.div | ||
| v-if="visible" | ||
| class="CommandPalette" | ||
| :initial="{ opacity: 0, y: '-100px' }" | ||
| :animate="{ opacity: 1, y: '0' }" | ||
| :exit="{ opacity: 0, y: '-100px' }" | ||
| @click.stop="visible = false" | ||
| @keydown.enter.stop | ||
| > | ||
| <div class="container" @click.stop> | ||
| <input | ||
| ref="input" | ||
| v-model="query" | ||
| type="text" | ||
| placeholder="Search actions..." | ||
| @keydown.enter.prevent="trigger(actions[0])" | ||
| /> | ||
| <div class="scroll-container"> | ||
| <ul> | ||
| <li v-for="(action, i) in actions" :key="i"> | ||
| <button @click="trigger(action)"> | ||
| <SvgIcon v-if="action.icon" :name="action.icon" class="icon" /> | ||
| <div v-else class="icon-placeholder"></div> | ||
| <!-- eslint-disable vue/no-v-html --> | ||
| <span class="entry-content" v-html="action.highlighted.name"></span> | ||
| <!-- eslint-enable --> | ||
| <div class="shortcuts"> | ||
| <KeyboardShortcut | ||
| v-for="(shortcut, j) in action.shortcuts" | ||
| :key="j" | ||
| :shortcut="shortcut" | ||
| /> | ||
| </div> | ||
| </button> | ||
| </li> | ||
| <li v-if="!actions.length" class="disabled">No actions found</li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </motion.div> | ||
| </AnimatePresence> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .CommandPalette { | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| z-index: 2; | ||
| cursor: pointer; | ||
| font-size: 14px; | ||
| color: var(--color-text); | ||
| max-height: 100vh; | ||
|
|
||
| &::before { | ||
| content: ''; | ||
| position: absolute; | ||
| inset: 0; | ||
| top: -100px; | ||
| height: calc(100% + 200px); | ||
| background: var(--color-dim); | ||
| } | ||
| } | ||
|
|
||
| .container { | ||
| position: absolute; | ||
| top: 50%; | ||
| left: 50%; | ||
| transform: translate(-50%, -50%); | ||
| background-color: var(--color-app-bg); | ||
| border-radius: var(--radius-default); | ||
| backdrop-filter: blur(8px); | ||
| cursor: default; | ||
| padding: 1em; | ||
| display: flex; | ||
| flex-flow: column nowrap; | ||
| gap: 1em; | ||
| max-width: 32em; | ||
| } | ||
|
|
||
| .scroll-container { | ||
| overflow-y: auto; | ||
| height: 20em; | ||
| width: 100%; | ||
| padding-right: 0.5em; | ||
| } | ||
|
|
||
| input { | ||
| background: none; | ||
| width: calc(100% + 2em); | ||
| margin: 0 -1em; | ||
| padding: 0 2em 0.5em 2em; | ||
| border-bottom: 0.1px solid rgb(0 0 0 / 0.2); | ||
| } | ||
|
|
||
| button { | ||
| display: flex; | ||
| gap: 0.75em; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .icon, | ||
| .icon-placeholder { | ||
| display: inline-block; | ||
| color: var(--color-text); | ||
| } | ||
|
|
||
| .icon-placeholder { | ||
| width: 1em; | ||
| } | ||
|
|
||
| .entry-content { | ||
| margin-right: auto; | ||
| } | ||
|
|
||
| .shortcuts { | ||
| display: flex; | ||
| gap: 0.5em; | ||
| color: var(--color-text-secondary); | ||
| } | ||
|
|
||
| li { | ||
| color: var(--color-primary); | ||
| border-radius: var(--radius-default); | ||
| padding: 0.2em 1em; | ||
|
|
||
| &:focus-within { | ||
| background-color: var(--color-menu-entry-selected-bg); | ||
| } | ||
|
|
||
| &:not(.disabled):hover { | ||
| background-color: var(--color-menu-entry-hover-bg); | ||
| } | ||
|
|
||
| button { | ||
| width: 100%; | ||
| text-align: left; | ||
| border-radius: var(--radius-default); | ||
| } | ||
| } | ||
|
|
||
| :deep(.highlighted) { | ||
| color: var(--color-text); | ||
| font-weight: bold; | ||
| } | ||
| </style> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I thought I fixed it in one of the commits, but it seems it got lost…