import React, { useEffect } from 'react'; const getLanguageMode = (filename = '') => { const ext = filename.split('.').pop()?.toLowerCase(); switch (ext) { case 'js': case 'jsx': return 'JavaScript / React'; case 'ts': case 'tsx': return 'TypeScript / React'; case 'py': return 'Python'; case 'json': return 'JSON'; case 'html': return 'HTML'; case 'css': return 'CSS'; case 'sh': return 'Bash / Shell'; case 'md': return 'Markdown'; default: return 'Plain Text'; } }; export default function CodeEditor({ filename, value, onChange, onSave }) { const language = getLanguageMode(filename); useEffect(() => { const handleKeyDown = (e) => { if ((e.ctrlKey || e.metaKey) && e.key === 's') { e.preventDefault(); if (onSave) onSave(); } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [onSave]); const lineCount = (value || '').split('\n').length; const lineNumbers = Array.from({ length: Math.max(lineCount, 1) }, (_, i) => i + 1); return (
{/* Editor Status Bar */}
{filename || 'Untitled'} {language}
Lines: {lineCount} Press Ctrl+S to save
{/* Main Textarea Area with Line Numbers */}
{/* Line Numbers Sidebar */}
{lineNumbers.map((num) => (
{num}
))}
{/* Text Input Surface */}