Skip to content

Commit

Permalink
fix: make quick find keyboard shortcut work (#25)
Browse files Browse the repository at this point in the history
Adds event listeners for cmd+k and ctrl+k. When triggered, sends a
message to the parent (storm).

Adds support for the shortcut when the header or sidebars are selected.
Still does not work on the puck preview iframe because we cannot add a
listener to that iframe from outside the puck package.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Kilpatrick <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2024
1 parent d770a47 commit c4e1fca
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,24 @@ export const Editor = ({ document, componentRegistry }: EditorProps) => {
TARGET_ORIGINS
);

const { sendToParent: openQuickFind } = useSendMessageToParent(
"openQuickFind",
TARGET_ORIGINS
);

const keyboardHandler = (event: KeyboardEvent) => {
if ((event.ctrlKey || event.metaKey) && event.key === "k") {
openQuickFind();
}
};

useEffect(() => {
window.addEventListener("keydown", keyboardHandler);
return () => {
window.removeEventListener("keydown", keyboardHandler);
};
}, []);

const isLoading =
!puckConfig ||
!templateMetadata ||
Expand Down

0 comments on commit c4e1fca

Please sign in to comment.