Skip to content

Commit

Permalink
feat: add quick search opener keyboard shortcut for Mac platform
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Jul 12, 2024
1 parent a5234ad commit d6d7102
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/QuickSearchOpener.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import LucideFileSearch from "~icons/lucide/file-search";
class="btn btn-outline w-full justify-between border-base-content/50"
@click="open()"
@keydown.ctrl.k.window.prevent="open()"
@keydown.cmd.k.window.prevent="open()"
>
<div class="flex items-center gap-2">
<LucideFileSearch class="size-6" />
Quick search &hellip;
</div>
<kbd>
<kbd class="hidden font-normal text-base-content lg:kbd lg:kbd-sm">Ctrl</kbd>
<kbd class="hidden font-normal text-base-content lg:kbd lg:kbd-sm" x-text="cmdSymbol()">⌘</kbd>
<kbd class="hidden font-normal text-base-content lg:kbd lg:kbd-sm">K</kbd>
</kbd>
</button>
4 changes: 4 additions & 0 deletions src/scripts/alpine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type QuickSearchOpener = {
dialog: HTMLDialogElement | undefined;
init(): void;
open(): void;
cmdSymbol(): string;
};

const quickSearchOpener = (Alpine: Alpine) => {
Expand All @@ -37,6 +38,9 @@ const quickSearchOpener = (Alpine: Alpine) => {
this.dialog.showModal();
}
},
cmdSymbol(): string {
return navigator.userAgent.includes("Mac") ? "⌘" : "Ctrl";
},
}) as QuickSearchOpener,
);
};
Expand Down

0 comments on commit d6d7102

Please sign in to comment.