Skip to content

Commit f643d86

Browse files
committed
feat: Implement a command palette with Ctrl-K shortcut
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent ccbfa2d commit f643d86

7 files changed

Lines changed: 943 additions & 0 deletions

File tree

src/CollectivesApp.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
<CollectiveSettings
2323
v-if="showCollectiveSettings"
2424
:collective="settingsCollective" />
25+
<CommandPalette />
2526
</NcContent>
2627
</template>
2728

2829
<script>
2930
import { NcContent } from '@nextcloud/vue'
3031
import { mapActions, mapState } from 'pinia'
3132
import CollectiveSettings from './components/Nav/CollectiveSettings.vue'
33+
import CommandPalette from './components/CommandPalette.vue'
3234
import NavigationBar from './components/NavigationBar.vue'
3335
import PageSidebar from './components/PageSidebar.vue'
3436
import { useNetworkState } from './composables/useNetworkState.js'
3537
import { useCollectivesStore } from './stores/collectives.js'
38+
import { useCommandPaletteStore } from './stores/commandPalette.js'
3639
import { usePagesStore } from './stores/pages.js'
3740
import { useRootStore } from './stores/root.js'
3841
import { useSettingsStore } from './stores/settings.js'
@@ -43,6 +46,7 @@ export default {
4346
4447
components: {
4548
CollectiveSettings,
49+
CommandPalette,
4650
NcContent,
4751
NavigationBar,
4852
PageSidebar,
@@ -102,6 +106,11 @@ export default {
102106
103107
mounted() {
104108
this.getCollectivesAndSettings()
109+
this.setupKeyboardShortcuts()
110+
},
111+
112+
beforeDestroy() {
113+
this.removeKeyboardShortcuts()
105114
},
106115
107116
methods: {
@@ -110,6 +119,7 @@ export default {
110119
'getCollectives',
111120
'getTrashCollectives',
112121
]),
122+
...mapActions(useCommandPaletteStore, { toggleCommandPalette: 'toggle' }),
113123
114124
async getCollectivesAndSettings() {
115125
this.loadPending = true
@@ -137,6 +147,22 @@ export default {
137147
138148
this.loadPending = false
139149
},
150+
151+
setupKeyboardShortcuts() {
152+
document.addEventListener('keydown', this.handleGlobalKeyDown)
153+
},
154+
155+
removeKeyboardShortcuts() {
156+
document.removeEventListener('keydown', this.handleGlobalKeyDown)
157+
},
158+
159+
handleGlobalKeyDown(event) {
160+
// Check for Cmd+K (Mac) or Ctrl+K (Windows/Linux)
161+
if ((event.metaKey || event.ctrlKey) && event.key === 'k') {
162+
event.preventDefault()
163+
this.toggleCommandPalette()
164+
}
165+
},
140166
},
141167
142168
}

0 commit comments

Comments
 (0)