Skip to content

Commit 6e4b7d4

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

7 files changed

Lines changed: 948 additions & 0 deletions

File tree

src/CollectivesApp.vue

Lines changed: 27 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'
32+
import CommandPalette from './components/CommandPalette.vue'
3133
import CollectiveSettings from './components/Nav/CollectiveSettings.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: {
@@ -111,6 +120,8 @@ export default {
111120
'getTrashCollectives',
112121
]),
113122
123+
...mapActions(useCommandPaletteStore, { toggleCommandPalette: 'toggle' }),
124+
114125
async getCollectivesAndSettings() {
115126
this.loadPending = true
116127
if (!this.networkOnline) {
@@ -137,6 +148,22 @@ export default {
137148
138149
this.loadPending = false
139150
},
151+
152+
setupKeyboardShortcuts() {
153+
document.addEventListener('keydown', this.handleGlobalKeyDown)
154+
},
155+
156+
removeKeyboardShortcuts() {
157+
document.removeEventListener('keydown', this.handleGlobalKeyDown)
158+
},
159+
160+
handleGlobalKeyDown(event) {
161+
// Check for Cmd+K (Mac) or Ctrl+K (Windows/Linux)
162+
if ((event.metaKey || event.ctrlKey) && event.key === 'k') {
163+
event.preventDefault()
164+
this.toggleCommandPalette()
165+
}
166+
},
140167
},
141168
142169
}

0 commit comments

Comments
 (0)