MCPcopy Create free account
hub / github.com/Railly/tinte / CodeInput

Function CodeInput

apps/ray/src/components/code-input.tsx:11–66  ·  view source on GitHub ↗
({
  code,
  onChange,
  language,
  onLanguageChange,
}: CodeInputProps)

Source from the content-addressed store, hash-verified

9}
10
11export function CodeInput({
12 code,
13 onChange,
14 language,
15 onLanguageChange,
16}: CodeInputProps) {
17 const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
18 if (e.key === "Tab") {
19 e.preventDefault();
20 const target = e.currentTarget;
21 const start = target.selectionStart;
22 const end = target.selectionEnd;
23 const newValue = `${code.substring(0, start)} ${code.substring(end)}`;
24 onChange(newValue);
25 requestAnimationFrame(() => {
26 target.selectionStart = start + 2;
27 target.selectionEnd = start + 2;
28 });
29 }
30 };
31
32 return (
33 <div className="flex flex-col gap-2 h-full">
34 <div className="flex items-center gap-2">
35 <label
36 htmlFor="language-select"
37 className="text-xs text-muted-foreground"
38 >
39 Language
40 </label>
41 <select
42 id="language-select"
43 value={language}
44 onChange={(e) => onLanguageChange(e.target.value as Language)}
45 className="text-xs bg-accent border rounded px-2 py-1 text-foreground outline-none cursor-pointer hover:border-ring transition-colors"
46 >
47 {LANGUAGES.map((lang) => (
48 <option key={lang} value={lang}>
49 {lang}
50 </option>
51 ))}
52 </select>
53 </div>
54 <textarea
55 value={code}
56 onChange={(e) => onChange(e.target.value)}
57 onKeyDown={handleKeyDown}
58 spellCheck={false}
59 className="flex-1 w-full bg-accent border rounded-lg p-4 font-mono text-xs leading-relaxed text-foreground outline-none resize-none hover:border-ring focus:border-ring transition-colors"
60 style={{
61 fontFamily: "var(--font-geist-mono), 'Fira Code', Menlo, monospace",
62 }}
63 />
64 </div>
65 );
66}

Callers

nothing calls this directly

Calls 1

onChangeFunction · 0.50

Tested by

no test coverage detected