Skip to content

Commit 58fdc13

Browse files
Add ⌘K keyboard shortcut to focus search input
- Add Cmd+K / Ctrl+K keyboard shortcut that focuses the search input - Show a ⌘K badge inside the search input when not focused and empty - Badge hides when input is focused or has a query Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
1 parent 976cf29 commit 58fdc13

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/App.svelte

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
// Copy toast
3636
let copiedModel = "";
3737
38+
// Search input ref and focus tracking
39+
let searchInput: HTMLInputElement;
40+
let searchFocused = false;
41+
42+
function handleKeydown(e: KeyboardEvent) {
43+
if ((e.metaKey || e.ctrlKey) && e.key === "k") {
44+
e.preventDefault();
45+
searchInput?.focus();
46+
}
47+
}
48+
3849
// Quick start tab state per model
3950
let codeTabStates: Record<string, "sdk" | "proxy"> = {};
4051
@@ -295,6 +306,8 @@ We also need to update [${RESOURCE_BACKUP_NAME}](https://github.com/${REPO_FULL_
295306
}
296307
</script>
297308

309+
<svelte:window on:keydown={handleKeydown} />
310+
298311
<main class="container">
299312
<!-- Hero Section -->
300313
<div class="hero">
@@ -370,7 +383,10 @@ We also need to update [${RESOURCE_BACKUP_NAME}](https://github.com/${REPO_FULL_
370383
</svg>
371384
<input
372385
id="query"
386+
bind:this={searchInput}
373387
bind:value={query}
388+
on:focus={() => { searchFocused = true; }}
389+
on:blur={() => { searchFocused = false; }}
374390
type="text"
375391
autocomplete="off"
376392
name="query"
@@ -383,6 +399,9 @@ We also need to update [${RESOURCE_BACKUP_NAME}](https://github.com/${REPO_FULL_
383399
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
384400
</button>
385401
{/if}
402+
{#if !query && !searchFocused}
403+
<kbd class="search-shortcut">⌘K</kbd>
404+
{/if}
386405
</div>
387406

388407
<ProviderDropdown bind:selectedProvider {providers} />
@@ -925,6 +944,26 @@ curl http://0.0.0.0:4000/v1/chat/completions \
925944
926945
.search-clear:hover { color: var(--text-color); background: var(--bg-tertiary); }
927946
947+
.search-shortcut {
948+
position: absolute;
949+
right: 0.75rem;
950+
top: 50%;
951+
transform: translateY(-50%);
952+
display: inline-flex;
953+
align-items: center;
954+
justify-content: center;
955+
padding: 0.125rem 0.4375rem;
956+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
957+
font-size: 0.6875rem;
958+
font-weight: 500;
959+
color: var(--muted-color);
960+
background: var(--bg-secondary);
961+
border: 1px solid var(--border-color);
962+
border-radius: 5px;
963+
pointer-events: none;
964+
line-height: 1.4;
965+
}
966+
928967
/* Filters */
929968
.filters-row {
930969
display: grid;

0 commit comments

Comments
 (0)