Files
headquarter/apps/web/src/components/code-editor.tsx
T
Fusion 7261c75bb2 feat: implement file editor with syntax highlighting and editing
- Install react-simple-code-editor and prismjs dependencies
- Create language detection utility with 50+ file extensions
- Create SyntaxHighlighter component with Prism.js highlighting
- Create CodeEditor component with syntax-highlighted editing
- Create CommitDialog with diff preview and commit message
- Create FileEditor component integrating view/edit/commit flow
- Replace FileViewer with FileEditor in RepoWorkspace
- Add comprehensive CSS styles for editor, highlighter, and dialog
- Support keyboard shortcuts: Ctrl+E (toggle edit), Ctrl+S (save)
- Quality gates: typecheck ✓ lint ✓ build ✓
2026-05-19 16:04:48 +02:00

57 lines
1.3 KiB
TypeScript

import React, { useEffect } from "react";
import Editor from "react-simple-code-editor";
import { highlightCode, loadLanguage } from "../utils/language";
interface CodeEditorProps {
value: string;
onChange: (value: string) => void;
language: string;
readOnly?: boolean;
}
export const CodeEditor: React.FC<CodeEditorProps> = ({
value,
onChange,
language,
readOnly = false,
}) => {
useEffect(() => {
const highlight = async () => {
await loadLanguage(language);
};
void highlight();
}, [language]);
const hightlightWithLineNumbers = (input: string) =>
input
.split("\n")
.map(
(line, i) =>
`<div class="editor-line"><span class="editor-line-number">${
i + 1
}</span><span class="editor-line-content">${highlightCode(
line || " ",
language
)}</span></div>`
)
.join("");
return (
<div className="code-editor">
<Editor
value={value}
onValueChange={onChange}
highlight={hightlightWithLineNumbers}
padding={0}
className="editor-textarea"
textareaClassName="editor-textarea-input"
readOnly={readOnly}
style={{
fontFamily: '"Fira Code", "Monaco", "Courier New", monospace',
fontSize: 14,
}}
/>
</div>
);
};