|
20 | 20 | import { clickOutside } from '$lib/actions/clickoutside'; |
21 | 21 | import { goto } from '$app/navigation'; |
22 | 22 | import SidebarConfig from './SidebarConfig.svelte'; |
| 23 | + import { onMount, onDestroy } from 'svelte'; |
| 24 | + import { browser } from '$app/environment'; |
23 | 25 |
|
24 | 26 | interface Props { |
25 | 27 | assistant?: Assistant; |
|
36 | 38 | let credDialog: HTMLDialogElement; |
37 | 39 | let credAuth: ReturnType<typeof CredentialAuth>; |
38 | 40 | let configDialog: HTMLDialogElement; |
| 41 | + let shortcutsDialog: HTMLDialogElement; |
39 | 42 |
|
40 | 43 | async function createNewThread() { |
41 | 44 | const thread = await ChatService.createThread(project.assistantID, project.id); |
|
69 | 72 | } |
70 | 73 | }); |
71 | 74 | }); |
| 75 | +
|
| 76 | + function handleKeydown(event: KeyboardEvent) { |
| 77 | + // Ctrl + E for edit mode |
| 78 | + if (event.ctrlKey && event.key === 'e') { |
| 79 | + event.preventDefault(); |
| 80 | + layout.projectEditorOpen = !layout.projectEditorOpen; |
| 81 | + } |
| 82 | +
|
| 83 | + // Ctrl + T for thread panel |
| 84 | + if (event.ctrlKey && event.key === 't') { |
| 85 | + event.preventDefault(); |
| 86 | + layout.sidebarOpen = !layout.sidebarOpen; |
| 87 | + layout.fileEditorOpen = false; |
| 88 | + } |
| 89 | +
|
| 90 | + // Ctrl + H for keyboard shortcuts help |
| 91 | + if (event.ctrlKey && event.key === 'h') { |
| 92 | + event.preventDefault(); |
| 93 | + shortcutsDialog?.showModal(); |
| 94 | + } |
| 95 | + } |
| 96 | +
|
| 97 | + onMount(() => { |
| 98 | + if (browser) { |
| 99 | + window.addEventListener('keydown', handleKeydown); |
| 100 | + } |
| 101 | + }); |
| 102 | +
|
| 103 | + onDestroy(() => { |
| 104 | + if (browser) { |
| 105 | + window.removeEventListener('keydown', handleKeydown); |
| 106 | + } |
| 107 | + }); |
72 | 108 | </script> |
73 | 109 |
|
74 | 110 | <div class="colors-background relative flex h-full flex-col overflow-hidden"> |
|
235 | 271 | /> |
236 | 272 | </div> |
237 | 273 | </dialog> |
| 274 | + |
| 275 | + <dialog |
| 276 | + bind:this={shortcutsDialog} |
| 277 | + class="default-dialog" |
| 278 | + use:clickOutside={() => shortcutsDialog?.close()} |
| 279 | + > |
| 280 | + <div class="p-6"> |
| 281 | + <button class="absolute top-0 right-0 p-3" onclick={() => shortcutsDialog?.close()}> |
| 282 | + <X class="icon-default" /> |
| 283 | + </button> |
| 284 | + <h3 class="mb-4 text-lg font-semibold">Keyboard Shortcuts</h3> |
| 285 | + <div class="space-y-4"> |
| 286 | + <div class="grid grid-cols-2 gap-2"> |
| 287 | + <div class="font-medium">Ctrl + E</div> |
| 288 | + <div>Toggle Edit Mode</div> |
| 289 | + |
| 290 | + <div class="font-medium">Ctrl + T</div> |
| 291 | + <div>Toggle Thread Panel</div> |
| 292 | + |
| 293 | + <div class="font-medium">Ctrl + H</div> |
| 294 | + <div>Show Keyboard Shortcuts</div> |
| 295 | + </div> |
| 296 | + </div> |
| 297 | + </div> |
| 298 | + </dialog> |
238 | 299 | </main> |
239 | 300 | </div> |
240 | 301 | </div> |
0 commit comments