Connect, collaborate, and grow with a community of TypeScript developers
fix: editor shortcuts and vimconfig styling (#554)
kualta429d10856c0b
diff --git a/apps/web/src/app/challenge/[id]/wrapper.tsx b/apps/web/src/app/challenge/[id]/wrapper.tsxindex 6f5338d8..2e4bb871 100644--- a/apps/web/src/app/challenge/[id]/wrapper.tsx+++ b/apps/web/src/app/challenge/[id]/wrapper.tsx@@ -2,7 +2,7 @@import { useSelectedLayoutSegments } from 'next/navigation';import { CodePanel } from '@repo/monaco';import { useSession } from '@repo/auth/react';-import { SettingsButton } from '../_components/settings/settings-button';+import { SettingsButton } from '../_components/editor-settings/editor-settings-button';import type { ChallengeRouteData } from './getChallengeRouteData';import { SubmissionOverview } from './submissions/_components/overview';import { saveSubmission } from './submissions/save-submission.action';diff --git a/apps/web/src/app/challenge/_components/settings/settings-button.tsx b/apps/web/src/app/challenge/_components/editor-settings/editor-settings-button.tsxsimilarity index 95%rename from apps/web/src/app/challenge/_components/settings/settings-button.tsxrename to apps/web/src/app/challenge/_components/editor-settings/editor-settings-button.tsxindex 7b75fc0c..96843abe 100644--- a/apps/web/src/app/challenge/_components/settings/settings-button.tsx+++ b/apps/web/src/app/challenge/_components/editor-settings/editor-settings-button.tsx@@ -9,7 +9,7 @@ import {TooltipTrigger,} from '@repo/ui';import { Settings } from '@repo/ui/icons';-import { SettingsForm } from './settings-form';+import { SettingsForm } from './editor-settings-form';export function SettingsButton() {return (diff --git a/apps/web/src/app/challenge/_components/settings/settings-form.tsx b/apps/web/src/app/challenge/_components/editor-settings/editor-settings-form.tsxsimilarity index 82%rename from apps/web/src/app/challenge/_components/settings/settings-form.tsxrename to apps/web/src/app/challenge/_components/editor-settings/editor-settings-form.tsxindex a09dd24c..63f71f60 100644--- a/apps/web/src/app/challenge/_components/settings/settings-form.tsx+++ b/apps/web/src/app/challenge/_components/editor-settings/editor-settings-form.tsx@@ -40,6 +40,7 @@ export function SettingsForm() {resolver: zodResolver(formSchema),defaultValues: settings,});+ const isVimBindings = form.getValues().bindings === 'vim';function onSubmit(data: FormSchema) {updateSettings(data);@@ -55,12 +56,12 @@ export function SettingsForm() {return (<Form {...form}>- <form onSubmit={form.handleSubmit(onSubmit)}>+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-4"><FormFieldcontrol={form.control}name="fontSize"render={({ field }) => (- <FormItem className="mb-3">+ <FormItem><FormLabel>Font Size</FormLabel><Select defaultValue={field.value} onValueChange={field.onChange}><FormControl>@@ -89,7 +90,7 @@ export function SettingsForm() {control={form.control}name="tabSize"render={({ field }) => (- <FormItem className="mb-3">+ <FormItem><FormLabel>Tab Size</FormLabel><Select defaultValue={field.value} onValueChange={field.onChange}><FormControl>@@ -110,12 +111,12 @@ export function SettingsForm() {control={form.control}name="bindings"render={({ field }) => (- <FormItem className="mb-3">+ <FormItem><FormLabel>Key Bindings</FormLabel><Select defaultValue={field.value} onValueChange={field.onChange}><FormControl><SelectTrigger>- <SelectValue placeholder="Select a font size" />+ <SelectValue placeholder="Select Key Binding Style" /></SelectTrigger></FormControl><SelectContent>@@ -127,23 +128,25 @@ export function SettingsForm() {</FormItem>)}/>- <FormField- control={form.control}- name="vimConfig"- render={({ field: { value, ...field } }) => (- <FormItem className="mb-3">- <FormLabel>Vim Config</FormLabel>- <Textarea- value={value || DEFAULT_SETTINGS.vimConfig}- className="resize-none font-mono"- {...field}- />- <FormMessage />- </FormItem>- )}- />+ {isVimBindings ? (+ <FormField+ control={form.control}+ name="vimConfig"+ render={({ field: { value, ...field } }) => (+ <FormItem>+ <FormLabel>Vim Config</FormLabel>+ <Textarea+ value={value || DEFAULT_SETTINGS.vimConfig}+ className="h-60 resize-none font-mono"+ {...field}+ />+ <FormMessage />+ </FormItem>+ )}+ />+ ) : null}- <DialogFooter>+ <DialogFooter className="mt-3"><DialogPrimitive.Close asChild><Button type="submit">Save</Button></DialogPrimitive.Close>diff --git a/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-button.tsx b/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-button.tsxindex 88b8f5ed..915aba5c 100644--- a/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-button.tsx+++ b/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-button.tsx@@ -8,8 +8,8 @@ import {TooltipContent,TooltipTrigger,} from '@repo/ui';-import { Command } from '@repo/ui/icons';import { EditorShortcuts } from './editor-shortcuts-form';+import { SquareSlash } from '@repo/ui/icons';export function EditorShortcutsButton() {return (@@ -17,7 +17,7 @@ export function EditorShortcutsButton() {<DialogTrigger><Tooltip><TooltipTrigger asChild>- <Command className="stroke-zinc-500 stroke-1 hover:stroke-zinc-400" size={20} />+ <SquareSlash className="stroke-zinc-500 stroke-1 hover:stroke-zinc-400" size={20} /></TooltipTrigger><TooltipContent className="px-2 py-1">Shortcuts</TooltipContent></Tooltip>diff --git a/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-form.tsx b/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-form.tsxindex 9330951c..fd958246 100644--- a/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-form.tsx+++ b/apps/web/src/app/challenge/_components/editor-shortcuts/editor-shortcuts-form.tsx@@ -1,26 +1,37 @@'use client';+import type { PropsWithChildren } from 'react';+interface Props {title: string;description: React.ReactNode;}+function EditorShortcut(props: Props) {return (<div className="grid grid-cols-2 gap-2"><h1>{props.title}</h1>- <>{props.description}</>+ {props.description}</div>);}+const Key = (props: PropsWithChildren) => {+ return (+ <kbd className="rounded-md border border-zinc-300 bg-neutral-200 p-1 py-0.5 font-mono text-xs text-zinc-600 dark:border-zinc-600 dark:bg-zinc-700 dark:text-zinc-300">+ {props.children}+ </kbd>+ );+};+export function EditorShortcuts() {return (- <div>+ <div className="flex flex-col gap-2"><EditorShortcuttitle="Run Code"description={<p>- <kbd>Ctrl</kbd> + <kbd>'</kbd>+ <Key>Ctrl</Key> + <Key>'</Key></p>}/>@@ -28,7 +39,7 @@ export function EditorShortcuts() {title="Submit"description={<p>- <kbd>Ctrl</kbd> + <kbd>Enter</kbd>+ <Key>Ctrl</Key> + <Key>Enter</Key></p>}/>@@ -36,7 +47,7 @@ export function EditorShortcuts() {title="Debug Code"description={<p>- <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>'</kbd>+ <Key>Ctrl</Key> + <Key>Alt</Key> + <Key>'</Key></p>}/>@@ -44,7 +55,7 @@ export function EditorShortcuts() {title="To indent one level"description={<p>- <kbd>Tab</kbd> + <kbd>Ctrl</kbd>+ <Key>Tab</Key> + <Key>Ctrl</Key></p>}/>@@ -52,7 +63,7 @@ export function EditorShortcuts() {title="To indent one fewer levels"description={<p>- <kbd>Shift</kbd> + <kbd>Tab</kbd>+ <Key>Shift</Key> + <Key>Tab</Key></p>}/>@@ -60,7 +71,7 @@ export function EditorShortcuts() {title="To move lines up/down"description={<p>- <kbd>Alt</kbd> + <kbd>Up/Down</kbd>+ <Key>Alt</Key> + <Key>Up/Down</Key></p>}/>@@ -68,7 +79,7 @@ export function EditorShortcuts() {title="Delete line and copy to buffer"description={<p>- <kbd>Ctrl</kbd> + <kbd>X</kbd>+ <Key>Ctrl</Key> + <Key>X</Key></p>}/>@@ -76,7 +87,7 @@ export function EditorShortcuts() {title="Comment/uncomment current selection"description={<p>- <kbd>Ctrl</kbd> + <kbd>/</kbd>+ <Key>Ctrl</Key> + <Key>/</Key></p>}/>@@ -84,7 +95,7 @@ export function EditorShortcuts() {title="Undo action"description={<p>- <kbd>Ctrl</kbd> + <kbd>Z</kbd>+ <Key>Ctrl</Key> + <Key>Z</Key></p>}/>@@ -92,7 +103,7 @@ export function EditorShortcuts() {title="Redo action"description={<p>- <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Z</kbd>+ <Key>Ctrl</Key> + <Key>Shift</Key> + <Key>Z</Key></p>}/>diff --git a/apps/web/src/components/wizard/TestCasesEditor.tsx b/apps/web/src/components/wizard/TestCasesEditor.tsxindex a8b1e3c3..aa2b5a50 100644--- a/apps/web/src/components/wizard/TestCasesEditor.tsx+++ b/apps/web/src/components/wizard/TestCasesEditor.tsx@@ -8,7 +8,7 @@ import dynamic from 'next/dynamic';import { createTwoslashInlayProvider } from '@repo/monaco/twoslash';import { PrettierFormatProvider } from '@repo/monaco/prettier';import type { WizardForm } from '.';-import { SettingsButton } from '~/app/challenge/_components/settings/settings-button';+import { SettingsButton } from '~/app/challenge/_components/editor-settings/editor-settings-button';const VimStatusBar = dynamic(() => import('@repo/monaco/vim-mode'), {ssr: false,diff --git a/packages/ui/src/icons.ts b/packages/ui/src/icons.tsindex e54ca283..33fe1ca8 100644--- a/packages/ui/src/icons.ts+++ b/packages/ui/src/icons.ts@@ -34,6 +34,7 @@ export {Settings,Settings2,Share,+ SquareSlash,Sun,ThumbsUp,Trash2,