Skip to content

Commit

Permalink
feat(editor): add hotkey snippet for run button
Browse files Browse the repository at this point in the history
  • Loading branch information
purfectliterature committed Apr 12, 2023
1 parent 0a10aea commit 9852d5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useFile from '../hooks/useFile';
import useFilesMutations from '../hooks/useFilesMutations';

import Button from './Button';
import K from './Hotkey';

interface EditorProps {
onRunCode?: (code: string) => void;
Expand Down Expand Up @@ -72,6 +73,7 @@ const CoreEditor = (props: CoreEditorProps): JSX.Element => {
<div className="absolute bottom-3 right-3 space-x-2">
<Button icon={PlayIcon} onClick={saveThenRunCode}>
Run
<K className="ml-2 text-blue-900/60 ring-blue-900/60" of="F5" />
</Button>
</div>
)}
Expand Down
11 changes: 9 additions & 2 deletions src/components/Hotkey.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface HotkeyProps {
of: string;
className?: string;
}

const isMac = navigator.platform.startsWith('Mac');
Expand Down Expand Up @@ -30,12 +31,18 @@ const Hotkey = (props: HotkeyProps): JSX.Element => {

const keys = hotkey.split(SEPARATOR);

if (isMac) return <kbd>{keys.map(convert).join('')}</kbd>;
if (isMac)
return <kbd className={props.className}>{keys.map(convert).join('')}</kbd>;

return (
<>
{keys
.flatMap((key) => [<kbd key={key}>{convert(key)}</kbd>, SEPARATOR])
.flatMap((key) => [
<kbd key={key} className={props.className}>
{convert(key)}
</kbd>,
SEPARATOR,
])
.slice(0, -1)}
</>
);
Expand Down

0 comments on commit 9852d5b

Please sign in to comment.